typedef void question

S

Schüle Daniel

Hi,

$ cat main.cpp
#include <iostream>

//#define VOID void
typedef void VOID;

VOID foo() {
std::cout << "in foo" << std::endl;
}

void bar(VOID) {
std::cout << "in bar" << std::endl;
}

int main() {
foo();
bar();
return 0;
}

I am using g++ 4.2.2 and 3.4.6

the interesting thing is that g++4.2.* doesn't like
bar prototype. compiling it yields

main.cpp:10: error: ‘<anonymous>’ has incomplete type
main.cpp:10: error: invalid use of ‘VOID’
main.cpp: In function ‘int main()’:
main.cpp:10: error: too few arguments to function ‘void bar(<type error>)’
main.cpp:16: error: at this point in file

g++3.4.6 hat no problems with bar

and both compile foo without problems

what was wrong with the above defintion of bar
that g++ changed its behaviour?

Regards, Daniel

ps: using #define VOID void works of course with all compilers
 
A

Andrey Tarasevich

Schüle Daniel said:
...
what was wrong with the above defintion of bar
that g++ changed its behaviour?
...

Must be some glitch in gcc. Using a typedef-name for 'void' to declare an empty
parameter list is not allowed in C++. The wording in 8.3.5/2 is intended to mean
that it should be specifically spelled as '(void)' in order to make a valid
parameter declaration list.

There was an early defect report about this - #18

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#18

It's status is NAD - "not a defect", meaning that the standard was clear on that
from the very beginning.
 
S

Schüle Daniel

[...]
Must be some glitch in gcc. Using a typedef-name for 'void' to declare
an empty parameter list is not allowed in C++. The wording in 8.3.5/2 is
intended to mean that it should be specifically spelled as '(void)' in
order to make a valid parameter declaration list.

so it's an improvement in g++ standard compliance

I discovered this using opengl related code
/mesa/include/GL:[12]$ cat gl.h | awk '/^typedef.*void.*GLvoid;$/'
typedef void GLvoid;

hmm, there is no sense to typedef void

thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top