Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > typedef void question

Reply
Thread Tools

typedef void question

 
 
Schüle Daniel
Guest
Posts: n/a
 
      02-02-2008
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
 
Reply With Quote
 
 
 
 
Andrey Tarasevich
Guest
Posts: n/a
 
      02-02-2008
Schüle Daniel wrote:
> ...
> 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/wg...closed.html#18

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

--
Best regards,
Andrey Tarasevich
 
Reply With Quote
 
 
 
 
Schüle Daniel
Guest
Posts: n/a
 
      02-03-2008
[...]
>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a simple question about typedef void* KEYWORK jack C Programming 2 11-27-2009 01:23 PM
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments