integral type conversions
Fri Mar 24 12:54:00 GMT 2006
> If the source is a signed integral type and the destination is an
> unsigned integral type that is larger, are the additional bits done
> via sign extension or zero extension?
On 2's complement machines (the only sort I've ever used), the additional
bits are done via sign extension.
This behavior should be identical to the behavior in C.
Side note: I use the Java convention of converting a char to an int:
char c = '\xAA';
i = c & 0xFF;
Works the reliably on plain-char-is-signed and plain-char-is-unsigned
machines. Presuming the architecture is 8-bit-bytes (such as all my
platforms are). And I'm not sure if there's caveats for 1's complement
machines to worry about.
More information about the Gcc-help