Re: Goto?!? (was Re: A89: fwrite bug located (and a bugfix))


[Prev][Next][Index][Thread]

Re: Goto?!? (was Re: A89: fwrite bug located (and a bugfix))




Since I was bored... I decided to find out. Btw, doesn't casting of a
signed number to a unsigned number cause bad things?

Before I figured that out though, I did compile all 3 routines with -O2
-S... and here is what I get:

1.c = Novecks routine
1.c: In function `fread':
1.c:10: warning: comparison is always 1 due to limited range of data
type 
>   while (i++<n && (*(unsigned char*)ptr++=fgetc(f))>=0)
1.c:11: warning: comparison is always 1 due to limited range of data
type
>    while (j++<size && (*(unsigned char*)ptr++=fgetc(f))>=0)

2.c = Cowarts
2.c: In function `fread':
2.c:12: warning: comparison is always 0 due to limited range of data
type
>      if((*(unsigned char*)ptr++=fgetc(f))<0) goto exit;

And no they didn't produce the same code, although similar; there is an
extra loop in Novecks because of the seperate "while"s, which I thing
was to be expected. But what is notable is that the "goto exit" is
optimized out (totally) because the conditional always is true since (in
Cowart's/Zeljko's) a unsigned number can't be less than 0 (duh), and in
Novecks, a unsigned number is always >= 0.

> > nearly sure it works.  Can anyone find out if GCC is good enough to have
> > this output the proper code???
> >
> >     -Scott
> >
> >
> >

-- 
Scott "Wrath" Dial
wrath@calc.org
ICQ#3608935
Member of TCPA - tcpa.calc.org
PGP key available



References: