Recent

Author Topic: Drawing a cone  (Read 12170 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Drawing a cone
« Reply #15 on: March 01, 2017, 07:50:45 pm »
Sorry, I misunderstood. I thought the '()' at the end of gluNewQuadric was a typo, using C syntax. I did not realize that was valid syntax in fpc.
No need to apologize. If you are not familiar with these kind of thing then i can understand the mistake.

The () brackets after the function name are very important here because the function itself that is part of opengl is stored inside a variable.

When a would be your conedata, and b the variable that contains the pointer to the function then:
Code: [Select]
a := b;
will try to assign the function that is stored in b to a.

That is why you got the message from the compiler telling that type a and type b did not match.

That is also why it is very dangerous to overrule that with casting b to a pointer in order to get it stored in a, because then you are in fact storing/copying the pointer to the opengl function into a.

Hence the crash, as a pointer to a opengl function is not valid cone data.

Now adding the () behind b so that it looks like:
Code: [Select]
a := b();
Will tell the compiler that your intention is to call the function that is assigned to variable b, and use its return value to be assigned to variable a.

If not mistaken then mode delphi does this automatically for you, but mode objfpc is more or less forcing you to be explicit. Because in delphi, you would have to guess what the compiler is actually doing.

Quote
That does compile, and so far is not generating a run time error.
I really hope so, otherwise i would have a hard time explaining why the nehe code 'just' works :-)

 

TinyPortal © 2005-2018