2

Is there a gcc macro that allows me to identify whether something is being compiled in 64bit mode?

hookenz
  • 36,432
  • 45
  • 177
  • 286
  • http://stackoverflow.com/questions/5272825/detecting-64bit-compile-in-c – pna Dec 07 '11 at 01:50
  • Possible duplicate of [Detecting 64bit compile in C](https://stackoverflow.com/q/5272825/608639) – jww Nov 26 '18 at 04:15

2 Answers2

3

Duplicate Question: Is there a GCC preprocessor directive to check if the code is being compiled on a 64 bit machine?

__LP64__ Seems to be what you want.

Community
  • 1
  • 1
Daniel Placek
  • 765
  • 5
  • 16
  • 1
    Note that on Windows, 64bit compiles are indicated by `__LLP64__` (yes, even with `gcc`). See http://blogs.msdn.com/b/oldnewthing/archive/2005/01/31/363790.aspx for details. – FrankH. Dec 09 '11 at 14:42
1

And you could also, at least on Linux,

  #include <features.h>
  #include <endian.h>    // perhaps you skip that
  #include <limits.h>
  #include <stdint.h>

Then <bits/workdsize.h> gets included and gives you __WORDSIZE (either 64 or 32)

But why do you ask and why using the standard types provided by <stdint.h> is not enough for you?

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547