public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32291]  New: -Wformat either too picky or not picky enough
@ 2007-06-11 20:29 scovich at gmail dot com
  2007-06-11 20:50 ` [Bug c++/32291] " schwab at suse dot de
  2010-02-21  0:15 ` manu at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: scovich at gmail dot com @ 2007-06-11 20:29 UTC (permalink / raw)
  To: gcc-bugs

Compiling the following snippet with -Wformat (or -Wall) causes the compiler to
complain: "wformat-bug.C:8: warning: format '%u' expects type 'unsigned int',
but argument 2 has type 'uint32_t'"

The problem seems to be that stdint.h defines uint32_t as "long" in cygwin. I
realize that int != long on some platforms, but i686 isn't one of them. Why
should the user be forced to cast their uint32_t (read: 32-bit unsigned int) to
"unsigned int" before passing it to printf() when they are logically identical? 

On the other hand, there's no complaint about passing a signed integer into an
unsigned format or vice-versa, even though the output value might actually
change because of the oversight in those cases.

wformat.C:
=======================================
#include <cstdio>
#include <stdint.h>

int main() {
  uint32_t a = ~0;
  unsigned int b = a;
  uint32_t c = b;
  printf("%u\n", c); // warning (?)

  int d = c;
  unsigned e = d;
  printf("%d\n", e); // no warning
  printf("%u\n", d); // no warning
}


-- 
           Summary: -Wformat either too picky or not picky enough
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: scovich at gmail dot com
GCC target triplet: i686-pc-cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32291


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/32291] -Wformat either too picky or not picky enough
  2007-06-11 20:29 [Bug c++/32291] New: -Wformat either too picky or not picky enough scovich at gmail dot com
@ 2007-06-11 20:50 ` schwab at suse dot de
  2010-02-21  0:15 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab at suse dot de @ 2007-06-11 20:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2007-06-11 20:50 -------
It is not portable to pass a long when an int is expected.  But exchanging
unsigned and signed variants of the same type is always possible.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32291


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/32291] -Wformat either too picky or not picky enough
  2007-06-11 20:29 [Bug c++/32291] New: -Wformat either too picky or not picky enough scovich at gmail dot com
  2007-06-11 20:50 ` [Bug c++/32291] " schwab at suse dot de
@ 2010-02-21  0:15 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21  0:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2010-02-21 00:14 -------
Apart from Andrea's answer, you can use PRIu32 to print uint32_type. See
inttypes.h in your system for the complete list.

Closing.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32291


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-21  0:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-11 20:29 [Bug c++/32291] New: -Wformat either too picky or not picky enough scovich at gmail dot com
2007-06-11 20:50 ` [Bug c++/32291] " schwab at suse dot de
2010-02-21  0:15 ` manu at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).