Dave Anderson wrote:
Jun Koi wrote:
> Hi,
>
> I looked at configure.c, and find some code like this:
>
> void
> get_current_configuration(void)
> {
> FILE *fp;
> static char buf[512];
> char *p;
>
> #ifdef __alpha__
> target_data.target = ALPHA;
> #endif
> #ifdef __i386__
> target_data.target = X86;
> #endif
> #ifdef __powerpc__
> target_data.target = PPC;
> #endif
> #ifdef __ia64__
> target_data.target = IA64;
> #endif
> ...
> }
>
> I have few questions:
> - Is it correct that the above code want to find out the architecture
> (means target here) we are compiling our code on?
Exactly.
>
> - Who defined those architectures in the above code, like "__i386__"
> (in the check "#ifdef __i386__")? I guessed that the architecture is
> defined in a particular prototype file in /usr/include, but cannot
> find anything there. So I think that those macros are defined by
> compilation process of crash, but again I dont see anywhere in the
> source doing that.
I forget where they are defined, but they're available to any compiled
object without any explicit #include's, like this example on my x86_64
machine:
# cat tmp.c
main()
{
#ifdef __x86_64__
printf("hello world\n");
#endif
}
# make tmp
cc tmp.c -o tmp
# ./tmp
hello world
#
Dave
They are defined by the gcc preprocessor. To see what they look like on
your system, try:
gcc -E -dM - </dev/null
--Guy