Jump to content
  • Advertisement
Sign in to follow this  
riku

Endianness check at compile time

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

Hi! I am looking for a convinient way of checking endianness at compile time (using C++). Using boost/detail/endian.hpp might be a portable choice. I'd want to know if there exists a constant expression I could use as a template paramter or another way of hacking this together without using dirty preprocessor macros. -Riku

Share this post


Link to post
Share on other sites
Advertisement
Quote:
...compile time ... without using dirty preprocessor macros

In short No.
This is the only way to do it at compile time, runtime is easy but is no good for templates. Boost uses the macros to do this.

Share this post


Link to post
Share on other sites
Just to make a note, while most processors are locked into their endian-ness, there are procs out there that can be switched between little and big endian. So a runtime check would be the only way to know what mode they were currently running in.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rattrap
Just to make a note, while most processors are locked into their endian-ness, there are procs out there that can be switched between little and big endian. So a runtime check would be the only way to know what mode they were currently running in.


Can you give an example of such a processor ?

Share this post


Link to post
Share on other sites
Quote:
Original post by nmi
Quote:
Original post by Rattrap
Just to make a note, while most processors are locked into their endian-ness, there are procs out there that can be switched between little and big endian. So a runtime check would be the only way to know what mode they were currently running in.


Can you give an example of such a processor ?


See bi-endian hardware for a whole list. Also even if that wasn't the case there would be nothing wrong in having the compiler and compiled executable running on completely different architectures (it isn't common though).

Share this post


Link to post
Share on other sites
Quote:
Original post by CTar
See bi-endian hardware for a whole list. Also even if that wasn't the case there would be nothing wrong in having the compiler and compiled executable running on completely different architectures (it isn't common though).


It actually is pretty common to cross compile (have the compiler running on a different architecture to the target). Most console development happens this way. Anyone developing a game for the GameCube, PS2, Xbox 360 or PS3 for example will be doing this since the development tools run on an x86 PC and the game executable will be running on MIPS, PowerPC or an SPU depending on the system. The PowerPC based platforms have opposite endianness to the PC. Developing for mobile phones, PDAs or embedded devices will also typically involve cross compiling.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!