This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Info of gcc constants (defines) for native/host endianess
<suresh.t <at> philips.com> writes:
>
> hi,
>
> I would like to use the host endianess (LITTLE or BIG endian) information
> in my code. Can someone tell me what gcc flags are available for this
> purpose.
> I believe that gcc built for for different platforms (linux/solaris/hp
> etc) will interally have flags that can give this info.
> Can someone give me the specifics please.
Not quite what you ask for, but I found this code snippet lying about... can't
vouch for its correctness (let alone portability - looks like 32-bit only):
// detect computer architecture
union {double f; uint32 i[2];} etest;
etest.f = 1.0;
if (etest.i[1] == 0x3FF00000) Architecture = LITTLEENDIAN;
else if (etest.i[0] == 0x3FF00000) Architecture = BIGENDIAN;
else Architecture = NONIEEE;
Regards,
Lionel