This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/63417] New: scanf: problem handling %hhd format
- From: "subc2 at wp dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 30 Sep 2014 15:48:01 +0000
- Subject: [Bug c/63417] New: scanf: problem handling %hhd format
- Auto-submitted: auto-generated
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 <stdio.h>
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 <stdio.h>
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.