How to #ifdef by CompilerType ? GCC or VC++

前端 未结 3 1910
灰色年华
灰色年华 2020-12-14 08:45

I used #ifdef Win32 for safe calls alike sprintf_s but now I want to build project with MinGW and it\'s just wrong now. I need to use #ifdef

3条回答
  •  鱼传尺愫
    2020-12-14 09:47

    Preferably, you should resort to using portable symbols. I understand sometimes those symbols may not be defined, so you can see the Predef project for an extensive list of preprocessor macros regarding standards, compilers, libraries, operating systems and architectures that aren't portable.

    However, the function you specifically mention in this question has been included within the C11 standard as a part of Annex K.3, the bounds-checking interfaces (library).

    K.3.1.1p2 states:

    The functions, macros, and types declared or defined in K.3 and its subclauses are declared and defined by their respective headers if __STDC_WANT_LIB_EXT1__ is defined as a macro which expands to the integer constant 1 at the point in the source file where the appropriate header is first included

    Thus, you should place preference upon checking __STDC_WANT_LIB_EXT1__, and only use compiler-specific symbols when that doesn't exist.

提交回复
热议问题