This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]