Why does lint complain about this?

Geoff Rimmer geoff at cs.warwick.ac.uk
Wed Apr 26 09:02:56 AEST 1989


In article <75688 at ti-csl.csc.ti.com> ramey at 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 at csc.ti.com)
> TI Computer Science Center

Geoff

        +----------------------------------------------------------+
        |       GEOFF RIMMER -                                     |
        |               FRIEND OF FAX BOOTHS AND ANSI C            |
        |       geoff at 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 :-)



More information about the Comp.lang.c mailing list