Why doesn't this work? (3B2 problem)
Danny Boulet
dab at myrias.UUCP
Sun Mar 30 10:55:29 AEST 1986
something to say first...
The problem is that getchar returns an int (not a char). I've never used
either of the machines that you mention but my guess is that the Pyramid
does sign extension on char to int conversions and the 3B2 doesn't. Since
EOF is an integer (-1), the value 0xff gets assigned to your variable 'c'.
When you compare this character with EOF (-1) on a machine that does sign
extension, you get -1 vs -1. On a machine that doesn't do sign extension,
you get 255 vs -1.
The solution is simple - declare 'c' as an int instead of as a char.
More information about the Comp.lang.c
mailing list