Skip to main content
GameDev.net gamedev.net
🔒 Locked

C Portability Question

Started by Abominus Dec 14, 2001 at 1:07 PM 2 replies 300+ views
Original Post
Abominus
Abominus
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?
Stoffel
Stoffel
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.
Stoffel
Stoffel
Oooh, I like that better--seems less tricky. Too bad about the cast & warning, though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.