void parameter question

Started by
7 comments, last by Anon Mike 15 years, 9 months ago
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?
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).
Kippesoep
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....

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??
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.
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.
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.
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.
"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

This topic is closed to new replies.

Advertisement