Local function declaration seems to be permitted in gcc, and I found a discussion on this: Is there any use for local function declarations?
However, my question is: is it allowed by ISO C standard? If it is, how to explain the following phenomenon which makes it puzzling:
int main(void) {
int f(void);
f();
}
void g(void) {
/* g has no idea about f. It seems that the decl is limited within its
* scope */
f();
}
int f(void) {}
while
int main(void) {
int f(void);
f();
}
void f(void); /* error because disagreement with the local declaration (local
declaration goes beyound its scope?) */
void f(void) { /* definition here */ }
According to the C99 standard: function names are in the same naming category. So we shall discuss the scoping mechanism to explain this. But how?
Actually, I'm working on a compiler course project which requires us to implement a simplified version of C compiler. I was trying to deal with this case but got confused.
EDIT: I know it's a common knowledge that C is procedure-oriented and requires function names to be unique. But this local style of declaration stirs clear situation, and it's hard for me to understand its principle/rule.