J
Jeff
Hello everybody,
I have a question concerning function declarations. When exactly do you have
to declare functions if you want to use them? I have two functions main()
and foo(), respectively defined in main.c and foo.c. There is no declaration
of foo() inside main.c, but main() calls foo().
If I compile both files (using gcc's -c option), and then link them, main()
calls foo() without any problem. How come ? Wasn't I suppose to declare
foo() within main.c so main() could call it?
Moreover, what exactly is the use of static functions ? Why would you want
to restrict a function to a certain file ? I have read the part in the Brian
W. Kernighan and Dennis M. Ritchie book about static functions, but they
only say that it permits to hide names that the other part of the program
does not need to access.
Any help will be appreciated,
Cheers!
- Joseph
I have a question concerning function declarations. When exactly do you have
to declare functions if you want to use them? I have two functions main()
and foo(), respectively defined in main.c and foo.c. There is no declaration
of foo() inside main.c, but main() calls foo().
If I compile both files (using gcc's -c option), and then link them, main()
calls foo() without any problem. How come ? Wasn't I suppose to declare
foo() within main.c so main() could call it?
Moreover, what exactly is the use of static functions ? Why would you want
to restrict a function to a certain file ? I have read the part in the Brian
W. Kernighan and Dennis M. Ritchie book about static functions, but they
only say that it permits to hide names that the other part of the program
does not need to access.
Any help will be appreciated,
Cheers!
- Joseph