Subject: Re: Warnings and builds...
To: None <seebs@solon.com>
From: Mike Long <mikel@shore.net>
List: current-users
Date: 05/06/1997 10:43:55
>Date: Mon, 5 May 1997 21:38:29 -0500 (CDT)
>From: Peter Seebach <seebs@solon.com>
>
>Would anyone object to the patches it would take to make -current
>build cleanly with -Wformat?  I was having the inevitable "proc
>size mismatch" (it appears my Sun3 kernel has fallen out of date
>again), and I noticed that the code uses %d to print sizeof()...

No objection to the concept, although the actual patches would have to
be judged on their own merit.

>Of course, there's no *good* answer in that case (You can't tell
>whether sizeof()'s return should be %u or %lu), but I am fairly
>confident that %d is "wrong".  (Arguably, we don't care unless
>struct proc is expected to outgrow INT_MAX.)

Whenever an integer of unknown size is fed to *printf(), you should
cast it first.  In this case, you should use:

printf("%lu", (unsigned long)sizeof(FOO));

>So... Is this pointless nit-picking?  A good idea?

I think it's a good idea.

>Feedback appreciated, especially from people on the platforms (alpha
>comes to mind) where %d might actually be *wrong* for size_t, if
>size_t were unsigned long...

%d is wrong on the i386, which uses `unsigned int' for size_t.
-- 
Mike Long <mikel@shore.net>                http://www.shore.net/~mikel
"Every normal man must be tempted at times to spit on his hands,
hoist the black flag, and begin slitting throats." -- H.L. Mencken