Two points

Doug Gwyn gwyn at smoke.brl.mil
Sat Apr 6 09:39:45 AEST 1991


In article <3661 at inews.intel.com> bhoughto at hopi.intel.com (Blair P. Houghton) writes:
>In article <15705 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>>In article <3646 at inews.intel.com> bhoughto at nevin.intel.com (Blair P. Houghton) writes:
>>>	while ( ( c = (char) getchar() ) != (char)EOF )
>>Assuming that the loop is meant to handle all possible byte values,
>>this is also buggy.

By the way, the reason I harp on this particular example is because
I have seen a LOT of code fail due to exactly this (and the previous)
construct.  getchar() returns an int; therefore it is that int value
that should be tested against EOF before any possible conversion to a
char (which may or not be signed).  It is easy to get this right..



More information about the Comp.lang.c mailing list