Detecting 64bit compile in C

后端 未结 9 1278
醉酒成梦
醉酒成梦 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:21

    Use a compiler-specific macro.

    I don't know what architecture you are targeting, but since you don't specify it, I will assume run-of-the-mill Intel machines, so most likely you are interested in testing for Intel x86 and AMD64.

    For example:

    #if defined(__i386__)
    // IA-32
    #elif defined(__x86_64__)
    // AMD64
    #else
    # error Unsupported architecture
    #endif
    

    However, I prefer putting these in the separate header and defining my own compiler-neutral macro.

提交回复
热议问题