the type specifier that declares the identifier in 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.
请参阅下面提到的C程序.
void fn (struct st {int a;} a, struct st b) ;
struct st obj ;
struct st {int a;};
void fn(struct st a, struct st b);
你说:
I believe prototype had this limit because we can use some variable names in the prototype declarations too. These names may conflict with the variables in the same scope (as that of function prototype). Like below.
06002
So, to allow the above declarations the scope of prototype is limited. (Correct me if I am wrong)
Being allowed of /**/, it should be the programmer’s responsibility (as per coding practices) to add proper comments about the use of the language there. I believe there has to be ‘something’ other than providing assistance to comments. – Ganesh Gopalasubramanian
OK – believe away. Compatibility with what C++ did was the rest of the reason, and the argument names were added there to promote readability. See Stroustrup ‘Design and Evolution of C++’. Note that the names of the parameters in the prototype are not part of the interface – see the discussion on providing arguments by name instead of position. – Jonathan Leffler
I believe the question the OP is asking is “what’s the point of having function prototype scope at all?”. You answer, unfortunately, does not shed any light on it. Frankly, I have no idea either. If they simply wanted to limit the scope of named parameter declarations (in a non-defining declaration) as OP guesses, they could’ve done it without introducing a scope (as it is done in C++ for example). – AndreyT
@AndreyT: in a function definition, the arguments are local to the body of the function (it is no longer possible to hide an argument by a local variable in the outermost block of the body of the function). The prototype logically declares a type inside the function, and therefore should be scoped as defined – and hence, a type defined only in the function prototype cannot be used outside the function, and a function that cannot be called is of little benefit to anyone. – Jonathan Leffler
@Jonathan Leffler: You seem to be explaining why the parameter names were allowed (“compatibility with C++” – OK). What I’d like to know is the rationale for introducing the “function prototype scope”. Why did they see the need to introduce such a scope? C++ doesn’t do it that way. There’s no function prototype scope in C++. – AndreyT
@AndreyT Yeh! We both are drowning in the same boat
the type specifier that declares the identifier in 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.
请参阅下面提到的C程序.
void fn (struct st {int a;} a, struct st b) ;
struct st obj ;
struct st {int a;};
void fn(struct st a, struct st b);
你说:
I believe prototype had this limit because we can use some variable names in the prototype declarations too. These names may conflict with the variables in the same scope (as that of function prototype). Like below.
06002
So, to allow the above declarations the scope of prototype is limited. (Correct me if I am wrong)
Being allowed of /**/, it should be the programmer’s responsibility (as per coding practices) to add proper comments about the use of the language there. I believe there has to be ‘something’ other than providing assistance to comments. – Ganesh Gopalasubramanian
OK – believe away. Compatibility with what C++ did was the rest of the reason, and the argument names were added there to promote readability. See Stroustrup ‘Design and Evolution of C++’. Note that the names of the parameters in the prototype are not part of the interface – see the discussion on providing arguments by name instead of position. – Jonathan Leffler
I believe the question the OP is asking is “what’s the point of having function prototype scope at all?”. You answer, unfortunately, does not shed any light on it. Frankly, I have no idea either. If they simply wanted to limit the scope of named parameter declarations (in a non-defining declaration) as OP guesses, they could’ve done it without introducing a scope (as it is done in C++ for example). – AndreyT
@AndreyT: in a function definition, the arguments are local to the body of the function (it is no longer possible to hide an argument by a local variable in the outermost block of the body of the function). The prototype logically declares a type inside the function, and therefore should be scoped as defined – and hence, a type defined only in the function prototype cannot be used outside the function, and a function that cannot be called is of little benefit to anyone. – Jonathan Leffler
@Jonathan Leffler: You seem to be explaining why the parameter names were allowed (“compatibility with C++” – OK). What I’d like to know is the rationale for introducing the “function prototype scope”. Why did they see the need to introduce such a scope? C++ doesn’t do it that way. There’s no function prototype scope in C++. – AndreyT
@AndreyT Yeh! We both are drowning in the same boat