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: [email protected]
ReportedBy: [email protected]
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