| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"=?windows-1252?Q?Sch=FCle_Daniel?=" |
| Date: |
02 Feb 2008 01:37:15 PM |
| Object: |
typedef void question |
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
.
|
|
| User: "Andrey Tarasevich" |
|
| Title: Re: typedef void question |
02 Feb 2008 01:48:31 PM |
|
|
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/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.
--
Best regards,
Andrey Tarasevich
.
|
|
|
| User: "=?windows-1252?Q?Sch=FCle_Daniel?=" |
|
| Title: Re: typedef void question |
02 Feb 2008 08:40:05 PM |
|
|
[...]
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
.
|
|
|
|
|

|
Related Articles |
|
|