public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46907] New: printf width not properly working for negative numbers which are variables
@ 2010-12-12 15:42 adrian.hawryluk at gmail dot com
  2010-12-12 16:48 ` [Bug c/46907] " schwab@linux-m68k.org
  0 siblings, 1 reply; 2+ messages in thread
From: adrian.hawryluk at gmail dot com @ 2010-12-12 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: printf width not properly working for negative numbers
                    which are variables
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: adrian.hawryluk@gmail.com
              Host: Windows XP SP2
            Target: mingw32
             Build: 4.5.0


#include <stdio.h>
#include <math.h>

int main()
{
    char a = 0x7f;
    printf("%02x ", 0x80);
    printf("%02x ", (char)0x80);
    printf("%02x ", a + 1);
    printf("%02x ", ++a);
    printf("%02x ", a);
    return 0;
}

Result:
80 ffffff80 80 ffffff80 ffffff80

Given this test, it looks like it might have to do with promotion to an int (or
is it long?), which is fine, except that I used the width to stop this problem
from happening.  Looks sketchy.

C:\>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.0/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.0/configure
--enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions
--with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry
--enable-libstdcxx-debug --enable-version-specific-runtime-libs
--disable-werror --build=mingw32 --prefix=/mingw

Thread model: win32
gcc version 4.5.0 (GCC)

--
A


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

* [Bug c/46907] printf width not properly working for negative numbers which are variables
  2010-12-12 15:42 [Bug c/46907] New: printf width not properly working for negative numbers which are variables adrian.hawryluk at gmail dot com
@ 2010-12-12 16:48 ` schwab@linux-m68k.org
  0 siblings, 0 replies; 2+ messages in thread
From: schwab@linux-m68k.org @ 2010-12-12 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2010-12-12 16:48:42 UTC ---
The width in the format string is a minimum width.


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

end of thread, other threads:[~2010-12-12 16:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-12 15:42 [Bug c/46907] New: printf width not properly working for negative numbers which are variables adrian.hawryluk at gmail dot com
2010-12-12 16:48 ` [Bug c/46907] " schwab@linux-m68k.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).