Xref: utzoo comp.lang.c:19556 comp.unix.questions:14453 comp.sources.wanted:7814 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!agate!garnet.berkeley.edu!ked From: ked@garnet.berkeley.edu (Earl H. Kinmonth) Newsgroups: comp.lang.c,comp.unix.questions,comp.sources.wanted Subject: Re: lint won't verify printf formatting against variable types?? Keywords: lint, cc, printf_family, conquer, SysV/AT Message-ID: <25718@agate.BERKELEY.EDU> Date: 23 Jun 89 20:14:59 GMT References: <328@tree.UUCP> Sender: usenet@agate.BERKELEY.EDU Reply-To: ked@garnet.berkeley.edu (Earl H. Kinmonth) Organization: University of California, Berkeley Lines: 23 In article <328@tree.UUCP> stever@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.