Does Allegro have a function to check endianness?
Can someone post a snippet of a) how to tell what endianness the machine has b) how they would read/write an 32bit int?
You could read/write little e regardless of machine type then convert to big e if required. Sound about correct?
IIRC there's a define somewhere in the header files (maybe type.h?) so you can use #IFDEF to know the endianess. Also, there are defines for the target system (CPU and operating system).
FYI, Allegro defines endianness with ALLEGRO_LITTLE_ENDIAN or ALLEGRO_BIG_ENDIAN defined
What about this pseudocode?
'type' would be a primitive like int, float, etc.
Allegro aside, here are some macros I'm using in my lib, mainly a scrap of a lot of detection macros that I took here and there.
Well. Old and new GCC specific code, maybe. I had no problem with it on Solaris, AIX, Linux, Windows MinGW.
BTW I also had to detect 32 or 64 bits, and that little piece covered all my needs:
Your mileage may vary. It may only be right on my own os targets.
Edit:
BTW endianness is only a problem if you are having datas or networks communications between systems that are not the same endian or bits. Problems may arise if i.e you write a datafile containing dumps on A and read it on B, and that B is not the same bits / endianness as A.
Commonly when I need to write something I'm rarely dumping a int64, as it's not portable across all my targets ( a mix of 32/64bits ), and anyway I always htonX before dumping, and ntohX when reading the dump. That way data is consistent.
I'm not sure if I'm clear, but my dear I'm tired today X-D
It seems there is a definition somewhere in the header files (maybe type.h?) so you can check the endianness using #IFDEF. It specifies the target system's CPU and operating system.https://maxifoot.info/
You can perform a run time check easily enough.
bool BigEndian() { int pack = 'b' << 24 | 'e' << 16 | 'e' << 8 | 'l'; return (char*)(pack)[0] == 'b'; }
Beels live in memory.
Yes, as I said before, it's defined by Allegro depending on how Allegro was compiled
ALLEGRO_LITTLE_ENDIAN or ALLEGRO_BIG_ENDIAN
This is about what I have.
Written and Read as little. Convert to big if needed.