This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 4.8.2 -Wno-format feat/broken
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: phi gcc <phi dot gcc at gmail dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 3 Mar 2014 11:16:04 +0000
- Subject: Re: gcc 4.8.2 -Wno-format feat/broken
- Authentication-results: sourceware.org; auth=none
- References: <CADieKzs0zNc5R5Wo+=Koo8mTJsg-0jEqE3PzwYEWXpQ+gsQ1uw at mail dot gmail dot com>
On 2 March 2014 07:53, phi gcc wrote:
> CU82$ cc -c c.c -Wno-format # Expect no warnings
>
> CU82$ cc -c c.c -Wformat=0 # Expect no warnings
>
> gcc 4.8.2
> =======
>
> C4N1$ cc -c c.c
> c.c: In function 'f':
> c.c:13:1: warning: format '%llx' expects argument of type 'long long unsigned in
> t', but argument 2 has type 'uint64' [-Wformat=]
> { return printf("a=%#llx\n",a);
> ^
There should be no warning here, because you have no specified
-Wformat or -Wall, so that implies you are using a modified GCC, or
"cc" is a wrapper around GCC which passes some -W options.
> C4N1$ cc -c c.c -Wno-format # Expect no warning
> c.c: In function 'f':
> c.c:13:1: warning: format '%llx' expects argument of type 'long long unsigned in
> t', but argument 2 has type 'uint64' [-Wformat=]
> { return printf("a=%#llx\n",a);
> ^
This should not warn, and doesn't when I test it.
Again, it seems to me that you are using a modified GCC or a wrapper
around it that passes additional -W options.
> ==========================================
>
> This raise a question, what is the clean way with no warning and no
> runstring -W restriction to code this.
>
> I come to this (though I bumped in the L".." problem yesterday) but i
> fear it is not the way to do it.
>
> CU82$ more c.c
> #include <stdio.h>
>
> #ifdef __LP64__
> typedef unsigned long uint64;
> #define Y "l"
> #else
> typedef unsigned long long uint64;
> #define Y "l"
> #endif
>
>
> int f(uint64 a)
> { return printf("a=%#"Y"x\n",a);
> }
>
> I would have prefered "a=%#"L"x\n" as L would have men "l" or "ll"
> depending on ilp32/lp64 but unfortunalty L"..." is already taken.
>
> Any suggestion appreciated.
Put a space between the L and the following string.
return printf("a=%#" L "x\n",a);
Of course doing this is fragile and IMHO a bad idea, I would use a
better name for the macro than "L" or "Y"
> from printf("bla %llx bla\n",a); I want to stay away from
> printf(__LP64_?"bla %lx bla\n":"bla %llx bla\n",a);
> Impossible to fix an all project occurences accuratly.
This problem is already solved for you.
Why not just use uint64_t and PRIu64?
int f(uint64_t a)
{
return printf("a=%#" PRIu64 "x\n",a);
}