type casting problem

bukys at rochester.UUCP bukys at rochester.UUCP
Fri Jun 10 23:48:41 AEST 1983


As Dennis Ritchie points out, if the goal is for the code to be
portable to compilers which don't support unsigned chars, use a mask.

If, on the other hand, you just want to write it right, try

	char *cp;
	...
	checksum ^= *(unsigned char *)cp;

which does the cast before it's too late (before the dereference).
So, if the compiler supports unsigned characters, you're in.

Liudvikas Bukys



More information about the Comp.lang.c mailing list