This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Endian Macros - are there any defaults


On Fri, 2004-11-12 at 13:29 -0800, Daniel Kegel wrote:
> Stan Katz wrote:
> >>>I know that gcc defines some preprocessor macros that let the
> >>>preprocessor generate different code for different architectures (I'm
> >>>using some of them) but I can't seem to find any that tell me about
> >>>either data format (big or little endian) or invocation options. Does
> >>>anyone know of anything I can use.
> >>
> >>#include <endian.h>
> >>
> >>#if __BYTE_ORDER == __LITTLE_ENDIAN
> >>...
> >>#elif __BYTE_ORDER == __BIG_ENDIAN
> >>...
> >>#endif
> >>
> >>bits/endian.h is where __BYTE_ORDER is ultimately defined.
> > 
> > 
> > I can't find any endian.h file on my system, that may be because
> > unfortunately I'm using newlib
> 
> Oh, oops, endian.h is part of glibc!
endian.h is not covered by any standard.

bits/endian.h is glibc proprietary.

machine/endian.h is BSD proprietary. sys/endian.h and sys/param.h also
basically are BSD proprietary, but are a little more common than the
other approaches.

>   I'm not suggesting you use autoconf (though that would
> be cool if you could).
autoconf has checks suitable for this purpose, but you need to be
careful about using then:

Endianness is a compile-time feature, not a configuration-time feature.
Therefore you must not use any autoconf generated preprocessor symbol
referring to endianness to any public header being exported from the
source-tree.

> Let us know what you find out.  I've never used newlib myself.
Rule of thumb: In general, newlib tries to follow POSIX. In cases not
being covered by POSIX (Like this), newlib often mimics BSD.

Further: Arm endianness handling is broken in all versions of newlib,
comprising newlib-1.12.0. If wanting to support both endiannesses for
the arm, you will probably need newlib from CVS (>1.12.0).

Ralf



------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]