[Solved] why this program compiles fine in C11 but not in C99? [duplicate]


This was (apparently) changed in C11. C99§6.7/3:

If an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except for tags as specified in 6.7.2.3.

C11§6.7/3:

If an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except that:

a typedef name may be redefined to denote the same type as it currently does, provided that type is not a variably modified type;

— tags may be redeclared as specified in 6.7.2.3.

While I can’t find a rationale document for C11, my guess as to the reason for this change is to allow multiple struct typedefs, possibly over multiple headers. Since re-declaring struct/union/enum tags is allowed already and typedefing structs is a fairly common idiom.

Edit

@Lundin has found the rationale for this: it is to enhance compatibility with C++:

C++ allows a typedef redefinition with the same name as a previous typedef to appear in the same scope, as long as it names the same type. Some C compilers allow similar typedef redefinition as an extension, though C99 does not allow it. Adding benign typedef redefinition to C1x would enhance consistency with C++, standardize some existing practice, and safely eliminate a constraint that is unhelpful and an occasional nuisance to users.

7

solved why this program compiles fine in C11 but not in C99? [duplicate]