Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!ringworld.Eng.Sun.COM!eager From: eager@ringworld.Eng.Sun.COM (Michael J. Eager) Newsgroups: comp.lang.c Subject: Re: legal ANSI prototype? Message-ID: <141513@sun.Eng.Sun.COM> Date: 29 Aug 90 03:36:09 GMT References: <31530015@hpcvia.CV.HP.COM> Sender: news@sun.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, Ca. Lines: 55 In article <31530015@hpcvia.CV.HP.COM> brianh@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