After reading through the ANSI C Yacc grammar specification I noticed the following are all valid:
register x;
auto y;
static z;
extern q;
This seems strange to me, as my understanding of type would suggest that none of these variables have a type. What do these mean? How are they type checked? How much memory is allocated?
Before C99 if a type was not specified it defaulted to
int
this was supposed to be removed in C99 but many compilers support it even in C99 mode. For example inclang
even using-std=c99
I only receive the following warnings as opposed to errors:gcc
also only provides a warning in this case, although using the-pedantic-errors
flag will causegcc
to produce errors which is usually the case for extensions ingcc
and usually forclang
to but not in this case.If we look at the draft C99 standard the Forward section says:
and includes the following bullet:
Update
From the Rationale for International Standard—Programming Languages—C section
6.7.2
Type specifiers:The grammar you are using does predate C99 but as far as I can tell a newer version which is updated to reflect C11 does not differ much with respect to type specifiers in a declaration. So the grammar in this situation is not sufficient to enforce this constraint. You would have to goto the standard section
6.7.2
Type specifiers and see that it says: