Archived

This topic is now archived and is closed to further replies.

Abominus

C Portability Question

Recommended Posts

Abominus    122
Is the code ''unsigned long foo = 0xFFFF'' portable? Immediate values default to ''int'' right? So on a system which uses 16-bit ints and 32-bit longs, will the compiler treat the literal 0xFFFF as an int and signed extend it to 0xFFFFFFFF before assignment?

Share this post


Link to post
Share on other sites
Stoffel    250
Nope, it''s not portable and it won''t sign-extend.

however, this will:
unsigned long foo = -1;

This will give you all 1s in any two''s-compliment architecture.

Share this post


Link to post
Share on other sites