Path: utzoo!attcan!uunet!mcvax!ukc!warwick!geoff From: geoff@cs.warwick.ac.uk (Geoff Rimmer) Newsgroups: comp.lang.c Subject: Re: Why does lint complain about this? Message-ID: <1773@ubu.warwick.UUCP> Date: 25 Apr 89 23:02:56 GMT References: <75688@ti-csl.csc.ti.com> Sender: news@warwick.UUCP Organization: Computer Science, Warwick University, UK Lines: 86 In-reply-to: ramey@m2.csc.ti.com's message of 24 Apr 89 16:38:31 GMT In article <75688@ti-csl.csc.ti.com> ramey@m2.csc.ti.com (Joe Ramey) writes: > When I run lint on this program > > main() > { > try(0); > } > > try(foo) > char *foo; > { > } > > I get this output: > > trylint.c: > trylint.c(7): warning: argument foo unused in function try > try, arg. 1 used inconsistently trylint.c(8) :: trylint.c(3) > > Why does lint say that the arg. is used inconsistently? I thought > that zero could be assigned to any pointer type. Shouldn't lint > recognize the constant 0 and realize that it is compatible with (char *) ? > When lint sees try (0); it says "Hmm. The 0 looks like an integer type to me." So when it comes to the definition of try() and sees the argument is now a "char *", it barfs. If you want lint to know that the argument is actually a "char *", you can do either of the following things: (1) --> declare try() before main(): try (foo) char *foo; {} main() { try(0); } (2) --> cast the 0 to (char *): main() { try ( ( char* ) 0); } try(foo) char *foo; { } (3) --> (the best solution) GET AN ANSI C COMPILER, such as gcc !!! ^^^^^^^^^^^^^^^^^^^^^^ This way, you would code your program thus: void try (char *foo); /* function prototype tells gcc what the argument types are */ int main (void) /* 'void' means no arguments */ { try(0); /* gcc already knows that the argument is (char *) */ } void try (char *foo) { } How did people ever survive without function prototypes! :-) > Joe Ramey (ti-csl!ramey , ramey@csc.ti.com) > TI Computer Science Center Geoff +----------------------------------------------------------+ | GEOFF RIMMER - | | FRIEND OF FAX BOOTHS AND ANSI C | | geoff@uk.ac.warwick.emerald | | Computer Science, Warwick University, England. | | "Gimme a computer and I can do anything" (*) | +----------------------------------------------------------+ (*) as long as UNIX, emacs and gcc are also provided :-)