NetBSD-Users archive

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

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



On Wed, Jan 27, 2021 at 8:13 AM Martin Husemann <martin%duskware.de@localhost> wrote:
>
> On Wed, Jan 27, 2021 at 04:07:09PM +0300, Lord Vader wrote:
> > Hi!
> >
> > On different linuxes with gcc 8.x and 9.x there is __WORDSIZE, that is
> > either 32 or 64 depending on the architecture.
>
> The classic test is #ifdef _LP64
>
> You can check (assuming you are on amd64) with something like:
>
>         cc -dM -E - < /dev/null
>
> vs
>
>         cc -m32 -dM -E - < /dev/null
>
> (A similar check works elsewhere, but -m32 is machine dependend)

To add to Martin's reply, also be careful of x32. x32 will define
_x86_64 and _ILP32. That means you push and pop 64-bit registers in
your ASM, but you have 32-bit integers, longs and pointers in C.

Also see https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html.

Jeff


Home | Main Index | Thread Index | Old Index