NetBSD-Users archive

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

[9.1 AMD64 gcc] How to distinguish between AMD64 and I386 from C code?



Hi!

On different linuxes with gcc 8.x and 9.x there is __WORDSIZE, that is either 32 or 64 depending on the architecture.

Here I have:

===
$ uname -a
NetBSD amd64bsd9 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
$ cat 1.c
#include <stdio.h>
#include <limits.h>

int main()
{
        printf("bits=%d\n",WORD_BIT);
        return 0;
}
$ gcc 1.c
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /usr/libexec/ld.elf_so, for NetBSD 9.1, not stripped
$ ./a.out
bits=32
===

and further:

===
$ grep -R __WORDSIZE /usr/include/*
$ grep -R WORD_BIT /usr/include/*
/usr/include/amd64/limits.h:#define WORD_BIT    32
/usr/include/i386/limits.h:#define WORD_BIT     32
/usr/include/machine/limits.h:#define WORD_BIT  32
/usr/include/sys/common_limits.h:#define WORD_BIT       (__SIZEOF_INT__ * 8)
===



Home | Main Index | Thread Index | Old Index