This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/46907] New: printf width not properly working for negative numbers which are variables
- From: "adrian.hawryluk at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 12 Dec 2010 15:42:41 +0000
- Subject: [Bug c/46907] New: printf width not properly working for negative numbers which are variables
- Auto-submitted: auto-generated
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