Declaring a void parameter list with typedef non-standard

I have a piece of code (legacy code) that has code similar to the following:

typedef void SPECIAL_VOID; int func (SPECIAL_VOID) { ..... } 

GCC issues the following warning for this piece of code: Warning: # 494-D: Declaring a void parameter list with typedef is non-standard

Why is the GCC complaining and why is it non-standard?

+4
source share
1 answer

This has changed between C89 and C99.

C89 has (6.5.4.3):

The list of parameter types indicates types and can declare identifiers for function parameters. [...] a special case of void , since the only element in the list indicates that the function has no parameters.

In C99, this changes to (6.7.5.3p10; 6.7.6.3p10 in C11):

A special case of an unnamed parameter of type void as the only element in the list indicates that the function has no parameters.

Sometimes this means that in C89 only a valid void token (after preprocessing) is valid when declaring a 0-parameter function, while typedef is allowed on C99. However, this does not comply with the standard in accordance with defect report 157 :

Subclause 6.7.1 clearly states that this is the only parameter of type void (as opposed to using the void keyword), which indicates that the function does not accept any parameters. For clarity, subclause 6.5.4.3 should be rephrased to emphasize that it is a void type and not a void keyword.

For C ++, defect 577 brings C ++ in line with C99; resolution is not available in C ++ 11, but is present in the post-standard project n3376, so we can assume that it is present in the next version of the standard and probably in the first TC-C ++ 11. The value of typedef before void cannot depend on the parameter template for obvious reasons. Question Error g ++: '<anonymous> is of an incomplete type , discusses this problem with g ++ and indicates that g ++ will most likely continue to reject the code for now.

+5
source

Source: https://habr.com/ru/post/1446941/


All Articles