tech-toolchain archive

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

Re: host endianness



On Mon, Feb 08, 2010 at 06:08:32AM +0000, Christos Zoulas wrote:
> >
> >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;
> }
> 

That is rather a PITA because you need the host compiler in the wrong
part of the build system.

Something based on:
    (set $(echo a|od -h); [ $2 = 0a61 ] && echo little || echo big;)
probably avoids needin a host compiler.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index