Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!genrad!decvax!betz From: betz@decvax.UUCP Newsgroups: net.lang.c Subject: type casting problem Message-ID: <112@decvax.UUCP> Date: Thu, 9-Jun-83 11:23:10 EDT Article-I.D.: decvax.112 Posted: Thu Jun 9 11:23:10 1983 Date-Received: Thu, 9-Jun-83 13:25:51 EDT Lines: 28 I have been trying to write a CRC routine in C that is transportable between machines. In the process of doing this I have encountered the need to fetch unsigned characters through a char pointer. This has revealed a difference of opinion among the various C compilers that I have been using. Example: register char *bp; register unsigned int csum; csum ^= (unsigned) *bp++; Under VAX-11 C and under Berkeley C, the character fetched through bp ends up being sign extended in spite of the unsigned type cast. Under DECUS C and V7 unix C, the character is not sign extended. Which is correct? If the character is supposed to be sign extended, how do I fetch an unsigned character from a char pointer? (short of anding the resulting character with 0xFF) Under some compilers it is possible to declare a variable as unsigned char, but this is not a universal feature. Does anyone have any suggestions on how to make this code machine independant? Thanks in advance, David Betz decvax!betz