Jump to content
  • Advertisement


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


Bit wise storage is ???Machine Specific???. Huh?

This topic is 5796 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

ok, this is most likely a quick question I have seen dozens of coders use things like.
if (x&0x01)
and stuff similar but when I looked up in my compilers refrence files on how to do this it said that everything about it is machine specific and your code will be unportable.... This is more confusing to me then anything I have ever seen sence Windows uses them and it remains pretty darn portable. Quote- "The code will be non-portable since the organization of bits-within-bytes and bytes-within-words is machine dependent." So are the refrence files totally wrong, Did I miss understand something about them, or am I hallusinating windows being portable? heh.

Share this post

Link to post
Share on other sites
your code is, indeed, pretty damn portable.

The thing that isn''t portable about this sort of thing is byte ordering. Some machines put the most significant byte of an integer first ("Big-endian"), and some put the most significant byte last ("little-endian"). Some do completely schizo things ("middle-endian"). This won''t affect your hexadecimal constants, since they are automatically rearranged for you, but it does mean that if you''re transfering files between different architectures, you need to be careful about this.

printf("%d\n", (short int)0x0103); /* always prints 259 */
printf("%d\n", *((short int *)"\001\003")); /* only sometimes prints 259 */

Don''t listen to me. I''ve had too much coffee.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!