In C89, what is the scope of a function name in an "old style" function definition?

Is the next law C89?

void f(a)
char a[sizeof &f];
{
}

      

My thinking is yes, as the scope of an identifier declared outside any block scope starts immediately after the end of the declarator and continues until the end of the translation unit. Therefore, area "f" includes a list of announcements.

"gcc -pedantic -Wall" accepts it. "clang -pedantic -Wall" rejects it, as does lcc.

+3


source to share


1 answer


From C90 standard (shock impact)

(C90, 6.1.2.1) "Structure, union, and enumeration tags have a scope that begins immediately after the tag appears in the type specifier that declares the tag. Each enumeration constant has a scope that begins immediately after its defining enumerator appears in the enumeration list. Any other identifier has a scope that begins immediately after its declaration completes. "

So for me this is also a valid function declaration.



EDIT: The devil is in the details (word completion), and after thinking it through, I believe this is not a valid function declaration, since the declarator is not complete after void f(a)

.

void f(a)
char a[sizeof &f];
                   ^

      

^

here denotes where the declarator ends and where the scope begins f

.

+2


source







All Articles