legal ANSI prototype?

Michael J. Eager eager at ringworld.Eng.Sun.COM
Wed Aug 29 13:36:09 AEST 1990


In article <31530015 at hpcvia.CV.HP.COM> brianh at hpcvia.CV.HP.COM (brian_helterline) writes:
>Hello netland,
>
>I have a question regarding the ANSI interpretation of a prototype
>declaration.  My compiler accepts it, but a pc-lint program does not.
>I am interested in knowing which one is wrong.  Here it is:
>
>extern intSomeFunction( int );
>
>int main( void );
>int main( void )
>{
>	int i = SomeFunction( 5 );
>	return 0;
>}
>
>MSC takes this just fine but my pc-lint complains that SomeFunction
>is called without a prototype being in scope.  If I add a space in the
>prototype, then everybody is happy.  My question is
>	1) is that prototype legal ANSI?

The prototype is legal: the function name is intSomeFunction.  This
function is never referenced.  It's not clear that this is what you
intended.


>	2) Am I just lucky that MSC accepts it?

No luck involved.  MSC says that you have a call to SomeFunction which
is not declared so it gets a K&R style default declaration: it is assumed 
to return an integer and there is no checking on argument number or type.
This is the ANSI interpretation of undeclared functions.


>	3) Is my pc-lint broken because it misses it?

Misses what?  You write that lint complains that SomeFunction does not
have a declaration, which is the case.  Lint is warning you that you 
may have misspelled the name in a declaration, which is the case.  

>
>As to the reason why it is like that, some software I purchased the
>following for prototypes:
>
>#define IMPORT( t )	extern t
>
>IMPORT( int )SomeFunction( int );
>....

The preprocessor is supposed to insert whitespace after the expansion
of a macro.  If it doesn't and the define is as described, there seems
to be a preprocessor bug.  


-- Michael Eager



More information about the Comp.lang.c mailing list