I have the following code:
typedef void VOID; int f(void); int g(VOID);
which compiles just fine in C (using gcc 4.3.2 on Fedora 10). The same code compiled as C++ gives me the following error:
void.c:3: error: ‘<anonymous>’ has incomplete type void.c:3: error: invalid use of ‘VOID’
Now, this is something in external library and I would like the owner to fix that problem. So I have a question – does C++ standard forbids this construct? Could you give me a pointer/citation? The only thing I can recall is that function declaration with (void) to signal empty parameter list is deprecated in C++, but I don’t understand why typedefed VOID does not work.
Yes, as far as i know the second declaration is invalid in C++ and C89, but it is valid in C99.
From The C99 draft, TC2 (
6.7.5.3/10):It’s explicitly talking about the type ‘void’, not the keyword.
From The C++ Standard,
8.3.5/2:That it means the actual keyword with ‘void’, and not the general type ‘void’ can also be seen from one of the cases where template argument deduction fails (
14.8.2/2):It’s put clear by others, notable in one core language issue report here and some GCC bugreports linked to by other answers.
To recap, your GCC is right but earlier GCC versions were wrong. Thus that code might have been successfully compiled with it earlier. You should fix your code, so that it uses ‘void’ for both functions, then it will compile also with other compilers (comeau also rejects the second declaration with that ‘VOID’).