Jump to content
  • Advertisement
Sign in to follow this  
hexa

void parameter question

This topic is 3800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a silly question .... Is there any difference between these 3 declarations of non-parameter function (in this case it's OpenGL application) ? 1. int InitGL(); 2. int InitGL(void); 3. int InitGL(GLvoid); Which is the correct one?

Share this post


Link to post
Share on other sites
Advertisement
In C++, these 3 are all identical (GLvoid is just a typedef-ed alias for void), being functions that take no parameters.

In C, number 2 and 3 are identical (functions that take no parameters, as in C++). Number 1 takes any number of parameters (equivalent to "int InitGL(...);" in C++).

They're all valid (only the last-mentioned possibility is probably not what you intended).

Share this post


Link to post
Share on other sites
yes and no. These days the answer is that there is no difference at all. IIRC, In the old days

void func(void);

meant the func had no arguments, but

void func();

meant the args were unspecified (and you could perform some dirty trickery to retrieve the arguments). In general, i prefer int InitGL() because it requires less typing - it's all down to personal style....

Share this post


Link to post
Share on other sites
I can see why you would do stuff like

typedef float MyFloat;

but why do people do things like making aliases for void?? I've seen this in a number of projects and it doesn't seem to make any sense to me. I mean is void ever going to be anything but void??

Share this post


Link to post
Share on other sites
Quote:
Original post by Red Ant
but why do people do things like making aliases for void??

Because they were making aliases for everything, I suppose. I agree with you, though. A foolish consistency.

Share this post


Link to post
Share on other sites
GLvoid can, in some sense, have different meanings in different languages. As far as I know, the alias for GLvoid in OpenGL was for platforms where there is no void type at all.

In C, for example, a void parameter to a function means no parameter. But in other languages, no parameters is indicated by, well, not having any parameter at all. The GLvoid type can be "typedefed" to nothing when nothing is required, and to something (to void in C, for example) when something is required to indicate nothing.

So even for languages where there is no void type, and where no parameter is indicate by nothing at all, glEnd(GLvoid) is a correct prototype.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
So even for languages where there is no void type, and where no parameter is indicate by nothing at all, glEnd(GLvoid) is a correct prototype.

Can you give an example? Offhand, I don't know of any OpenGL-era languages which both needed this and had language facilities to allow it.

Share this post


Link to post
Share on other sites
No, I don't know of any example at the moment (although not sure I've known one at all since I heard about this years ago [rolleyes]). But the specification allows for it, and there's no drawback to it.

Share this post


Link to post
Share on other sites
"void" didn't always exist in C. "GLvoid" exists because for the C compilers that don't support "void" it just gets #defined to nothing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!