gcc 4.8.2 -Wno-format feat/broken

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

 



Hi All,

I have construct like this in a project.

#include <stdio.h>

#ifdef __LP64__
typedef unsigned long uint64;
#else
typedef unsigned long long uint64;
#endif


int f(uint64 a)
{ return printf("a=%#llx\n",a);
}


Basically we have 64 bits unsigned int in an application that is
compiled either ILP32 or LP64 (with ILP32 accepting long long)


The idea is to printf such 64 bits in a uniq printf() it sounds that
compilers have accepted for years the %ll for long long ilp32 or long
lp64 yet spitting a warning that can be shutted with -Wno-format or
-Wformat=0

Ex:
gcc 4.6.3
=======

CU82$ cc -c c.c # Expected 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]

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);
 ^

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);
 ^

C4N1$ cc -c c.c -Wformat=0    # 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);
 ^

The last two gcc invocation emits warings despite -Wformat, is that a
feature, or a bug ?

Or is there a yet another hard to follow option mechanism ?

==========================================

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.

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.

myprintf("bla %llx bla\n",a);

With myprintf() doing the %llx reduction to %lx in a temp buffer
before doing the real vprintf(tmpfmt,ap);
Not cpu cycle savy.

Thanx in advance for any helps
Cheers,
Phi




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux