(unsigned)char

utzoo!henry utzoo!henry
Thu Mar 11 17:29:19 AEST 1982


Casting a char value to unsigned in the V7 compiler does a very nice
job of something that is awkward to get otherwise:  zero-extending
rather than sign-extending a char.  The trouble is, that's a bug:  be
warned.  The official behavior of casts, according to DMR, is that
they act like assignment to a temporary variable of that type.  Which
means that casting char to unsigned goes via int the same way a normal
assignment does, and the sign gets extended.  This is fixed in DMR's
more recent C compilers (when I asked him, he wasn't sure whether the
3.0 compiler was recent enough).



More information about the Net.bugs.v7 mailing list