From: Mike M. <mel...@pc...> - 2003-04-16 17:36:04
|
On Wed, 16 Apr 2003, wg - drs wrote: > Hi Mike, > > Thanks for the quick response. When I'm looking through the header files I > noticed that all of the conversion macros go from the endian type to Machine > Endian. I guess the ./configure script must have detected the machine type > and defined the flags accordingly so i can build correctly? The ./configure script determines the machine endian-ness and #define's WORDS_BIGENDIAN in config.h if the machine is big endian or leaves it un-#define'd if the machine is little endian. Thus, if you code absolutely must include endian-specific code: #ifdef WORDS_BIGENDIAN /* this is big endian specific */ #else /* this is little endian specific */ #endif Endian-ness is determined at compile time, not run time, since a binary program should never have to figure this out at run time (if you know otherwise, I would sure like to hear about it). I stress the point that *IF* you must include endian-specific code in your program. For the most part, all you will want to do is load big or little endian numbers from a bytestream. I use the LE_* and BE_* macros in a lot of my code to handle this. For example: x = BE_16(&bytestream[2]) will take the 2 bytes at bytestream[2] and bytestream[3] and load them into x as a 16-bit big endian number. Hope this helps... -- -Mike Melanson |