legal ANSI prototype?

brian_helterline brianh at hpcvia.CV.HP.COM
Fri Aug 31 01:15:57 AEST 1990


>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?
>	2) Am I just lucky that MSC accepts it?
>	3) Is my pc-lint broken because it misses it?

>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 );
>....

	First of all, thanks to all who responded to my note.  I have
	since figured it exactly what is going on. 

	When MSC preprocesses the IMPORT( int )SomeFunction( int ), it
	does add a space to get extern int SomeFunction( int ) _BUT_ if
	you preprocess to a file, the space is _NOT_ there and your
	preprocess file is no longer equivalent to your source code.

	My pc-lint program _DOES NOT_ add the space when it expands the
	macro so the function prototype is different that what it
	should be with ANSI C.

	As a side question, if you preprocess a source file to another
	file, is that file required to compile the same as the source
	file?  I remember seeing some discussion on the net about it
	but I can't remember.



More information about the Comp.lang.c mailing list