tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: host endianness



In article <1265571540.101109.17086.nullmailer%galant.ukfsn.org@localhost>,
Iain Hibbert  <plunky%rya-online.net@localhost> wrote:
>On Sun, 7 Feb 2010, Iain Hibbert wrote:
>
>> Hi,
>>
>> (think this might be toolchain related, flame away if not :)
>>
>> In the native build of pcc(1), we use a pre-generated config.h which
>> contains HOST_(BIG|LITTLE)_ENDIAN and TARGET_(BIG|LITTLE)_ENDIAN
>> definitions which should really be provided at build time. I found
>> <bsd.endian.mk> which supplies TARGET_ENDIANNESS but nothing about the
>> host.
>>
>> Is it ok to add the test below so I can supply the HOST_*_ENDIAN symbol to
>> the pcc build as appropriate? Its basically a copy of the
>> MACHINE_ARCH/TARGET_ENDIANNESS test already there..
>
>Hm, except that test doesn't actually work.. seems that HOST_ARCH is
>actually _HOST_ARCH and it's not always set.
>
>any other suggestions to get the host endianness at build time?

compile and run:

#include <stdio.h>
union {
        int x;
        char c[4];
} z = {
        .x = ('4' << 24) | ('3' << 16) | ('2' << 8) | '1'
};

int
main(void)
{
        printf("%4.4s\n", z.c);
        return 0;
}



Home | Main Index | Thread Index | Old Index