From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31672 invoked by alias); 30 Sep 2014 15:48:11 -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 Received: (qmail 31443 invoked by uid 48); 30 Sep 2014 15:48:02 -0000 From: "subc2 at wp dot pl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/63417] New: scanf: problem handling %hhd format Date: Tue, 30 Sep 2014 15:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: subc2 at wp dot pl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg02779.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63417 Bug ID: 63417 Summary: scanf: problem handling %hhd format Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: subc2 at wp dot pl The following code runs properly on any UNIX-like operating system, but under Windows with GCC up to the version 4.8.1 (ports: MinGW, MinGW-w64, TDM-GCC) gives wrong results. file.c: #include int main() { int logical = 1; signed char s_char; scanf("%hhd", &s_char); if (s_char == 0) logical = s_char; printf("%d", logical); return 0; } C:\> gcc -std=gnu99 file.c C:\> a.exe 0 0 C:\> a.exe 1 0 C:\> a.exe 2 0 What's even more interesting, after compiling this code magic.c: #include int main() { int logical = 1; signed char s_char; scanf("%hhd", &s_char); if (s_char == 0) { int nothing = 0; logical = s_char; } printf("%d", logical); return 0; } C:\> gcc -std=gnu99 magic.c C:\> a.exe 0 0 C:\> a.exe 1 1 C:\> a.exe 2 1 everything is OK.