Archived

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

Abominus

C Portability Question

Recommended Posts

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
Or you can do this (it''s what I do):

unsigned long foo = ~((unsigned)0);

I put the cast in there for clarity. Some compilers assume it''s a signed int and may give a warning; you''d get the same results either way though.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites