public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63417] New: scanf: problem handling %hhd format
@ 2014-09-30 15:48 subc2 at wp dot pl
  2014-09-30 15:51 ` [Bug c/63417] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: subc2 at wp dot pl @ 2014-09-30 15:48 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/63417] scanf: problem handling %hhd format
  2014-09-30 15:48 [Bug c/63417] New: scanf: problem handling %hhd format subc2 at wp dot pl
@ 2014-09-30 15:51 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-09-30 15:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63417

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC does not provide scanf.  Most likely MinGW (and maybe even windows)'s scanf
does not provide a POSIX complaint scanf.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-30 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 15:48 [Bug c/63417] New: scanf: problem handling %hhd format subc2 at wp dot pl
2014-09-30 15:51 ` [Bug c/63417] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).