[Bug c/63417] New: scanf: problem handling %hhd format
subc2 at wp dot pl
gcc-bugzilla@gcc.gnu.org
Tue Sep 30 15:48:00 GMT 2014
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.
More information about the Gcc-bugs
mailing list