Skip to main content
GameDev.net gamedev.net
🔒 Locked

void parameter question

Started by hexa Jul 17, 2008 at 6:41 AM 7 replies 950+ views
Original Post
hexa
hexa
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?
Kippesoep
Kippesoep
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).
Kippesoep
RobTheBloke
RobTheBloke
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....

Red Ant
Red Ant
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??
Sneftel
Sneftel
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.
Brother Bob
Brother Bob
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.
Sneftel
Sneftel
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.
Brother Bob
Brother Bob
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.
Anon Mike
Anon Mike
"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.
-Mike

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.