Why doesn't this work? (3B2 problem)

Doug Gwyn gwyn at brl-smoke.ARPA
Mon Mar 24 09:31:39 AEST 1986


In article <276 at birtch.UUCP> ken at birtch.UUCP (Ken B) writes:
>	char c;
>
>	c=getchar();
>	if (c!=EOF)

getchar() returns an (int), not a (char).  EOF is an (int).
You're throwing away some of the bits returned by getchar(),
which happens not to matter in this case except when an EOF
is returned.

>This exact program works correctly on our Pyramid 90x,
>so I know its not just my program.

Oh, yes it is.  The Pyramid presumably treats (char) as
(signed char), while the 3B2 treats (char) as (unsigned char).
Therefore the pyramid will propagate the sign of the 8-bit subset
of the getchar() result that you stashed into c, whereas the 3B2
will not propagate the sign.  You have a machine-dependent bug.
Didn't "lint" catch this?



More information about the Comp.lang.c mailing list