From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15055 invoked by alias); 12 Dec 2010 15:42:50 -0000 Received: (qmail 15040 invoked by uid 22791); 12 Dec 2010 15:42:49 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX,TW_DC,TW_JL X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Dec 2010 15:42:42 +0000 From: "adrian.hawryluk at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46907] New: printf width not properly working for negative numbers which are variables X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: adrian.hawryluk at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 12 Dec 2010 15:42:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-12/txt/msg01287.txt.bz2 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 #include 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