Detecting 64bit compile in C

后端 未结 9 1252
醉酒成梦
醉酒成梦 2020-11-28 12:01

is there a C macro or some kind of way that i can check if my c program was compiled as 64bit or 32bit at compile time in C?

Compiler: GCC Operating systems that i n

9条回答
  •  独厮守ぢ
    2020-11-28 12:22

    An easy one that will make language lawyer squeem.

    if(sizeof (void *) * CHARBIT == 64) {
    ...
    }
    else {
    ...
    }
    

    As it is a constant expression an optimizing compiler will drop the test and only put the right code in the executable.

提交回复
热议问题