If a function(say a()) prototype is declared inside a function(say main()) does it mean that it cannot be used in functions other that main() function?
3 Answers
No that does not mean that. If the other functions declare it too, then the function can be used by those other functions too.
int main(void) {
void f(void);
f();
}
void g(void) {
void f(void);
f();
}
In this example, main declared function f locally and called it. But g does that same thing too. Both declarations refer to the same function.
2 Comments
David Heffernan
Well, you may as well declare it at outer unit scope if you are going to do that!
David Heffernan
I mean, what you say is correct, but I can't help feeling it's not quite what the question was driving at, but then again, I could be wrong....
In general things that you are able to declare inside a function (e.g. variables) are only in use for that function.
1 Comment
Karl Knechtel
I think you are confused between declarations and definitions.