public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ or does it?
@ 2011-08-06 21:40 Christopher Huang-Leaver
  2011-08-07  1:29 ` Jie Zhang
  2011-08-07  1:35 ` Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Christopher Huang-Leaver @ 2011-08-06 21:40 UTC (permalink / raw)
  To: gcc

Hello,

This isn't really a compiler bug, but it's something which the manual
doesn't describe too well so I thought I would point this out.

This page of the manual:
http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html#Common-Predefined-Macros

says this:
"
You should use these macros for testing like this:

          /* Test for a little-endian machine */
          #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

"
... except you shouldn't !

To test for a little-endian machine you do this;

#include <endian.h>
#if __BYTE_ORDER  == __LITTLE_ENDIAN

I hope this is helpful.  Keep up the great work!

Regards,

Chris


My test:

#include <iostream>
int main()
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
std::cout << "small end first\n";
#endif

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
std::cout << "big end first\n";
#endif

return 0;
}

Output:

small end first
big end first

gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-4.4.5/work/gcc-4.4.5/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.5
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu
--disable-altivec --disable-fixed-point --without-ppl --without-cloog
--enable-nls --without-included-gettext --with-system-zlib
--disable-werror --enable-secureplt --enable-multilib
--enable-libmudflap --disable-libssp --enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.5/python
--enable-checking=release --enable-java-awt=gtk --enable-objc-gc
--enable-languages=c,c++,java,objc,obj-c++,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.5
p1.2, pie-0.4.5'
Thread model: posix
gcc version 4.4.5 (Gentoo 4.4.5 p1.2, pie-0.4.5)


-- 
"They say great science is built on the shoulders of giants - not
here. At Aperture we do all our science from scratch; no hand
holding." - Cave Johnson, CEO Aperture Science.

Follow me on twitter:   @zeonglow

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-07  1:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-06 21:40 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ or does it? Christopher Huang-Leaver
2011-08-07  1:29 ` Jie Zhang
2011-08-07  1:35 ` Jonathan Wakely
2011-08-07  1:40   ` Jie Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).