C Builtin Funxions
David Herron, NPR Lover
david at ukma.UUCP
Mon Apr 21 08:45:46 AEST 1986
In article <2554 at utcsri.UUCP> greg at utcsri.UUCP (Gregory Smith) writes:
>In article <2524 at brl-smoke.ARPA> rbj at icst-cmr (root) writes:
>>...
>...
>On related point ( I'll explain why ), do y'all remember "Weird C
>behaviour"? One of the problems being that printf was being passed the
>wrong types?
>
>Well, lint can't catch this sort of thing because it is told by
>/*VARARGS*/ to keep its cotton-picken hands off any call of printf.
>Anyway, in order to check this, it needs to know (1) that printf,fprintf,
>sprintf are special cases, (2) how to interpret printf format strings.
>The format may be known only at run-time: printf(fmt_string,...).
>However, in view of the facts that printf's are frequent, and that mistakes
>in parameter types are fairly common, and that 95% of printf calls have
>string constants for formats, I would like to see lint do this. If
>the format parameter was not a string constant, you would be on your
>own of course. ...
Ok, there *is* a way to do this. One of the europeans (that guy that
had been doing Hack) posted a tool for aiding lint last year sometime.
It read through C programs looking for printf() calls. It looked at the
format string and for the associated arguments it inserted a function
call, something like:
int retint(i) int i; { return i; }
/* ... more similar functions ... */
f()
{
...
printf("i is %d\n", retint(i));
...
}
Now, if i is not an int then lint will know that it should be
and bitch. Also the retint() calls can be gotten rid of
with:
#define retint(i) (i)
>... The following is a borderline case:
>
> printf( c<' '|| c>'\176'? "\\%3o":"%c", c);
I dunno what it would do with this case...
One thing that occurs to me... do char's always get casted to ints
when they're arguments to functions?????
--
David Herron, cbosgd!ukma!david, david at UKMA.BITNET, david at uky.csnet
More information about the Comp.lang.c
mailing list