- A function must be either defined or prototyped, or both, before it is called.
- You can define it fully before you call it.
- You can prototype it before you call it.
- You must do one or the other; or both.
- You may only define a function once.
- You may prototype a function as often as you like, provided all prototypes are the same with regards to arguments and the return type.
All a prototype does is let the compiler know what arguments and what return type the function is to have, this way it can tell if you're being stupid or not by using it incorrectly.
A local prototype limits the scope of the function, assuming it hasn't been defined already, or prototyped already.
Code:
void foo( int x )
{
void bar( void ); /* prototype this for use in 'foo' */
... do whatever ...
bar( ); /* call bar */
}
int main( void )
{
bar( ); /*illegal, main does not know of 'bar'*/
foo( 5 ); /* legal, main knows of 'foo' */
}
void bar( void )
{
...whatever...
}
[edit] Added scope info. [/edit]
Quzah.