This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Robust detection of endianness at compile time.
- From: Brian Dessent <brian at dessent dot net>
- To: Lee Rhodes <lee at rhoba dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 29 Jul 2007 08:56:38 -0700
- Subject: Re: Robust detection of endianness at compile time.
- References: <002b01c7d1c1$0078ab70$0701a8c0@lee8075b>
- Reply-to: gcc-help at gcc dot gnu dot org
Lee Rhodes wrote:
> Since these header files
> define the correct answer for my platform I presume that they are
> automatically generated during installation of the compiler as neither
> header file appears as such in the build directory for a newly compiled GCC
> (for c/c++).
Standard C header files in /usr/include such as endian.h are part of the
libc. They are not part of the compiler. So no, they are not generated
during installation of gcc, they are part of libc and installed when
libc was installed.
> The recommended method to list all the predefined macros:
> echo "" | gcc -E -dM -x c - | sort
> doesn't list ANY of the above endian macros!
They are just regular ordinary #defines in a header file, which by
definition means they are not built-in. The above shows only the
defines that are built-in to the compiler/preprocessor, i.e. the state
of the preprocessor namespace before any header file or user code is
parsed.
> Questions:
> 1. Since the compiler clearly HAS to know endianess why isn't there a
> simple, robust way to test for it on all platforms without depending on a
> header?
As I said already, autoconf.
> 4. Why are these very basic platform constants NOT included in the -dM
> output list?
Because they are not built-in to the compiler (at least, not on the
platform you are using.)
Brian