From C23 §’6.2.1(4):
Every other identifier has scope determined by the placement of its declaration (in a declarator or type specifier). If the declarator or type specifier that declares the identifier appears outside of any block or list of parameters, the identifier has file scope, which terminates at the end of the translation unit. If the declarator or type specifier that declares the identifier appears inside a block or within the list of parameter declarations in a function definition, the identifier has block scope, which terminates at the end of the associated block. If the declarator or type specifier that declares the identifier appears within the list of parameter declarations in a function prototype (not part of a function definition), the identifier has function prototype scope, which terminates at the end of the function declarator. If an identifier designates two different entities in the same name space, the scopes might overlap. If so, the scope of one entity (the inner scope) will end strictly before the scope of the other entity (the outer scope). Within the inner scope, the identifier designates the entity declared in the inner scope’ the entity declared in the outer scope is hidden (and not visible) within the inner scope.
I am unsure about the restriction in bold. It seems to have been introduced in the technical corrigendum for C1X as a fix for defect report 345, but I am still not clear as to why it is needed. Doesn’t it follow automatically from the language syntax combined with the rules for scope termination that are mentioned just before this sentence?
For example, in the example provided in the defect report, parameter f
has block scope and function f
has file scope. According to the rules for scope termination, this means that parameter f
‘s scope terminates at the end of the block that represents function f
‘s body, whereas function f
‘s scope terminates at the end of the enclosing translation unit. Since the language grammar ensures that the block that represents function f
‘s body is fully contained within the translation unit, doesn’t it follow that parameter f
‘s scope ends before that of function f
? If so, isn’t the restriction in bold redundant?
4