bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] build: avoid printf format mismatch warnings


From: Nicolas Joly
Subject: Re: [PATCH] build: avoid printf format mismatch warnings
Date: Tue, 29 Sep 2009 19:55:06 +0200
User-agent: Mutt/1.5.8i

On Tue, Sep 29, 2009 at 01:14:05PM -0400, Joel E. Denny wrote:
[...]
> With the following test program, I haven't persuaded gcc to give me a 
> warning or error:
> 
> % cat >tmp.c <<EOF
> #include <stdio.h>
> int
> main (void)
> {
>   size_t i = 0;
>   printf ("%d\n", i);
>   return 0;
> }
> EOF
> % gcc -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align -Wcast-qual 
> -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast 
> -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes 
> -Werror tmp.c
> 
> Any ideas?

You'll have a warning on archs where sizeof(size_t) != sizeof(int)
such as x86_64 ...

njoly@ [~]> uname -a
Linux xxx.xxx.xxx.xxx 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 
x86_64 x86_64 GNU/Linux

When generating 64-bit binary,

njoly@ [~]> gcc -m64 -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align 
-Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast 
-Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes 
-Werror tmp.c
cc1: warnings being treated as errors
tmp.c: In function 'main':
tmp.c:6: warning: format '%d' expects type 'int', but argument 2 has type 
'size_t'

But not with 32-bit,

njoly@ [~]> gcc -m32 -std=gnu99 -Wall -Wextra -Wno-sign-compare -Wcast-align 
-Wcast-qual -Wformat -Wpointer-arith -Wwrite-strings -Wbad-function-cast 
-Wmissing-declarations -Wmissing-prototypes -Wshadow -Wstrict-prototypes 
-Werror tmp.c

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]