lint won't verify printf formatting against variable types??

John Macdonald jmm at eci386.uucp
Sat Jul 1 04:09:09 AEST 1989


In article <2271 at trantor.harris-atd.com> bbadger at x102c.harris-atd.com (Badger BA 64810) writes:
>In article <27729 at lll-winken.LLNL.GOV> berry at lll-crg.llnl.gov (Berry Kercheval) writes:
>>In article <441a30e5.8f55 at fiero.engin.umich.edu>, ejd at caen (Edward J Driscoll) writes:
>>>It [[ if(x==5); ]]is legal, but I would hope for a warning from such an 
>>> obvious semantic error.  
>>
>>Goodness, save me from useless warnings for perfectly good C
>>constructs.  This is NOT an "obvious" semantic error.  Have you never
>>done something like this?
>>
>>	/* skip to end of word */
>>	while(!isspace(*cp++));
>>
>However,
>	if(x==5); 
>most certainly is useless, in fact, 
>	if(<<expression>>);  
>is *completely* equivalent to 
>	<<expression>>;
>semantically.  This isn't true for ``while(<<expression>>);'', in general.
>Since this is an obvious abuse of syntax, I would *hope* --
>but not necessarily *expect* -- that lint would catch such an error.  

If you look at pre-processor expanded source, then it is certainly *NOT*
useless.  I have often used code like the following...

:
:
#ifdef DEBUG_ARGS
#   define SHOW_ARG(i) printf( "i is %d\n", (i) )
#else
#   define SHOW_ARG(i)
#endif
:
:
	if( arg_flag )
	    SHOW_ARG( arg );
:
:

which pre-processes into "if(<expr>);" except in the unusual case where
the SHOW_ARGS define is provided to do some debugging on that portion of
the code.  A similar variation is:

:
:
	if ( x_flag )
#ifdef SYSV
	    ; /* SYSV defaults to state x anyhow */
#else
#ifdef BSD
	    do_bsd_x( args );
#else
#ifdef XENIX
	    do_xenix_x( other_args );
#endif
#endif
#endif
:
:

where one porting variation generates an empty then statement.
-- 
"Software and cathedrals are much the same -          | John Macdonald
first we build them, then we pray" (Sam Redwine)      |   jmm at eci386



More information about the Comp.lang.c mailing list