How do I check OS with a preprocessor directive?

前端 未结 16 1628
星月不相逢
星月不相逢 2020-11-22 13:53

I need my code to do different things based on the operating system on which it gets compiled. I\'m looking for something like this:

#ifdef OSisWindows
// do         


        
16条回答
  •  面向向阳花
    2020-11-22 14:15

    Microsoft C/C++ compiler (MSVC) Predefined Macros can be found here

    I think you are looking for:

    • _WIN32 - Defined as 1 when the compilation target is 32-bit ARM, 64-bit ARM, x86, or x64. Otherwise, undefined
    • _WIN64 - Defined as 1 when the compilation target is 64-bit ARM or x64. Otherwise, undefined.

    gcc compiler PreDefined MAcros can be found here

    I think you are looking for:

    • __GNUC__
    • __GNUC_MINOR__
    • __GNUC_PATCHLEVEL__

    Do a google for your appropriate compilers pre-defined.

提交回复
热议问题