• Advertisement

Archived

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

C Portability Question

This topic is 5917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Oooh, I like that better--seems less tricky. Too bad about the cast & warning, though.

Share this post


Link to post
Share on other sites

  • Advertisement