Boost logo

Boost Users :

From: Mike Wilson (yg-boost-users_at_[hidden])
Date: 2003-04-21 15:25:45


Hi,

There is an application I use that always produces a little endian binary
file.
I have written a program to process this file.
As my program can port to both little/big endian platforms I have a #define
(LITTLE_ENDIAN_TARGET)
acting as a flag for the necessary byte swapping that is needed on the
big-endian platforms.

I was wondering if there is a better way to do this, so I searched the Web &
boost archives.
I found the following code snippet in the boost archives.

    bool isLittleEndian() {
        int temp = 1;
        return (*(char*)&temp) != 0;
    }

which is of some help (eliminating my #define).

However, I was wondering if there is a PP or mpl way of testing for
endian-ness at compile time.

For example, I'd like to do something like the following:

    const bool IsLittleEndian = ..to be determined automatically..;

I've got a gut feeling that I can't do the above at complile time, but maybe
something like Wave may do the job?

Thanks for any assistance in this matter.

Mike


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net