lint won't verify printf formatting against variable types??
Earl H. Kinmonth
ked at garnet.berkeley.edu
Sat Jun 24 06:14:59 AEST 1989
In article <328 at tree.UUCP> stever at tree.UUCP (Steve Rudek) writes:
>I was surprised to discover that neither cc nor lint comments when printf
>formatting doesn't match variable types--I thought lint complained about
>everything! In other words, lint won't comment on the following:
>int x;
>long y;
>printf ("x=%ld y=%d", x, y);
>
>I'm trying to get a game called "conquer" to work on a Microport SysV/AT
>machine where ints are 16 bits rather than the 32 bits the author expected.
One way to make sure code like this is reasonably portable is to always
write the format statement with casts.
printf ("x=%ld y=%d", (long) x, (int) y);
or preferably
printf ("x=%ld y=%ld", (long) x, (long) y);
A superfulous cast does not harm. Casting to a larger size makes sure
nothing will be lost.
More information about the Comp.unix.questions
mailing list