This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: integral type conversions
- From: John Love-Jensen <eljay at adobe dot com>
- To: Perry Smith <pedz at easesoftware dot net>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Fri, 24 Mar 2006 06:54:11 -0600
- Subject: Re: integral type conversions
Hi Perry,
> 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';
int i;
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.
Sincerely,
--Eljay