This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: GCC char* bug
- To: Geoff Keating <geoffk at geoffk dot org>
- Subject: Re: GCC char* bug
- From: Bruce Korb <bkorb at pacbell dot net>
- Date: Sat, 21 Jul 2001 06:59:23 -0700
- Cc: gcc-bugs at gcc dot gnu dot org, bkorb at pacbell dot net
- Organization: Home
- References: <3B58FDDE.FB122652@pacbell.net> <jmofqedf2p.fsf@geoffk.org>
Geoff Keating wrote:
> I'm not sure what code precisely you're reporting a bug about,
gcc/fixinc/fixincl.c
> but if you write
>
> char pz_cmp_star = -10;
> int ch;
>
> ch = getc (in_fp);
> ch &= 0xFF;
> if (ch != pz_cmp_star)
> abort();
>
> you will always hit the abort() since '(int)x & 0xFF' is never
> going to be -10.
Of course it won't. Sorry, I inserted the fix into the sample
code. The problem is this:
char ch = 0xF6;
FILE* fp = fopen( "test", "w+" );
int inch;
fputc( ch, fp );
rewind( fp );
inch = fgetc( fp );
if (ch != inch)
abort();
This should _never_ abort on a platform where libc and
the compiler agree on the sign-ed-ness of char. It
aborts on Linux with GCC. My claim is that that is wrong.
Either getc/fgetc needs fixing, or GCC does. Either way.