On Mon, 5 Jul 2004 11:54:49 UTC,
mm***@yahoo.co.uk (Douglas) wrote:
Hi,
When and why would you want to...
1)
//=============================
int main(){
int someFunction(void);//declaration
This makes the prototype of someFunction only visible in main but not
aywhere in the translation unit before the definition of it occures.
someFunction();
}
int someFunction(void){} //definition
//===============================
instead of.....
2)
//==============================
int someFunction(void); //declaration
This makes the prototype of the function visible throuth the whole
translation unit beginning at this point.
int main(){
someFunction(void);
}
int someFunction(void){} //prototype
//================================
Thanks, Douglas
This makes sense whenever you have a fuction you would use only in a
specific point. Here you says in the first exapmle that only main()
should know how to call somFunction() but no other fuction that is
declared before the definition of someFunction() itself what is a
declaration on itself.
Shortening the visibility of something to the only point it is really
needed in a translation unit can help to find mistakes in coding much
earlier than in golden code. As any try outside the points where the
prototype should be known gives you a diagnostic from the compier, so
you would check if either your code or your design has a flaw long
before you starts testing.
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation