chars in conditional expression, 3b2 C compiler
James Van Artsdalen
james at bigtex.uucp
Fri Jan 2 21:19:04 AEST 1987
IN article <189 at olamb.UUCP>, kimcm at olamb.UUCP (Kim Chr. Madsen) wrote:
> The only thing that really bugs me is the fact that chars are unsigned
> and therefore the following code will fail:
>
> while ((c=getc(stream)) != EOF) putchar(c);
>
> And you will have to redefine EOF to 255 (0377 or 0xff) or cast it to a char!
This code will fail no matter how chars are handled, assuming "c" is a "char".
If you remember that getc() returns an *int*, not a char, and have "int c"
instead of "char c", this works just fine.
If "c" is declared "char c;", the while loop above is broken even with signed
chars: what happens to the while loop if a 0xff is in the file? It terminates
early, whereas if c is "int c;" is works OK. lint will find this kind of bug.
--
James R. Van Artsdalen ...!ut-sally!utastro!bigtex!james "Live Free or Die"
Voice: (512)-323-2675 Modem: (512)-323-2773 5300B McCandless, Austin TX 78756
More information about the Comp.bugs.sys5
mailing list