Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Microsoft C/C++ compiler (MSVC) predefines certain preprocessor macros depending on the language (C or C++), the compilation target, and the chosen compiler options.
MSVC supports the predefined preprocessor macros required by the ANSI/ISO C99, C11, and C17 standards, and the ISO C++14, C++17, and C++20 standards. The implementation also supports several more Microsoft-specific preprocessor macros.
Some macros are defined only for specific build environments or compiler options. Except where noted, the macros are defined throughout a translation unit as if they were specified as /D compiler option arguments. When defined, the preprocessor expands macros their specified values before compilation. The predefined macros take no arguments and can't be redefined.
Standard predefined identifier
The compiler supports this predefined identifier specified by ISO C99 and ISO C++11.
__func__The unqualified and unadorned name of the enclosing function as a function-local static const array ofchar.void example() { printf("%s\n", __func__); } // prints "example"
Standard predefined macros
The compiler supports these predefined macros specified by the ISO C99, C11, C17, and ISO C++17 standards.
__cplusplusDefined as an integer literal value when the translation unit is compiled as C++. Otherwise, undefined.__DATE__The compilation date of the current source file. The date is a constant length string literal of the form Mmm dd yyyy. The month name Mmm is the same as the abbreviated month name generated by the C Runtime Library (CRT) asctime function. The first character of date dd is a space if the value is less than 10. This macro is always defined.__FILE__The name of the current source file.__FILE__expands to a character string literal. To ensure that the full path to the file is displayed, use/FC(Full Path of Source Code File in Diagnostics). This macro is always defined.__LINE__Defined as the integer line number in the current source file. The value of this macro can be changed by using a#linedirective. The integral type of the value of__LINE__can vary depending on context. This macro is always defined.__STDC__Defined as 1 when compiled as C and if the/Zacompiler option is specified. Starting in Visual Studio 2022 version 17.2, it's defined as 1 when compiled as C and if the/Zc:__STDC__compiler option is specified. Otherwise, undefined.__STDC_HOSTED__Defined as 1 if the implementation is a hosted implementation, one that supports the entire required standard library. Otherwise, defined as 0.__STDC_NO_ATOMICS__Defined as 1 if the implementation doesn't support optional standard atomics. The MSVC implementation defines it as 1 when compiled as C and one of the/stdC11 or C17 options is specified.__STDC_NO_COMPLEX__Defined as 1 if the implementation doesn't support optional standard complex numbers. The MSVC implementation defines it as 1 when compiled as C and one of the/stdC11 or C17 options is specified.__STDC_NO_THREADS__Defined as 1 if the implementation doesn't support optional standard threads. The MSVC implementation defines it as 1 when compiled as C and one of the/stdC11 or C17 options is specified.__STDC_NO_VLA__Defined as 1 if the implementation doesn't support standard variable length arrays. The MSVC implementation defines it as 1 when compiled as C and one of the/stdC11 or C17 options is specified.__STDC_VERSION__Defined when compiled as C and one of the/stdC11 or C17 options is specified. It expands to201112Lfor/std:c11, and201710Lfor/std:c17.__STDCPP_DEFAULT_NEW_ALIGNMENT__When/std:c17or later is specified, this macro expands to asize_tliteral that has the value of the alignment guaranteed by a call to alignment-unawareoperator new. Larger alignments are passed to an alignment-aware overload, such asoperator new(std::size_t, std::align_val_t). For more information, see/Zc:alignedNew(C++17 over-aligned allocation).__STDCPP_THREADS__Defined as 1 if and only if a program can have more than one thread of execution, and compiled as C++. Otherwise, undefined.__TIME__The time of translation of the preprocessed translation unit. The time is a character string literal of the form hh:mm:ss, the same as the time returned by the CRT asctime function. This macro is always defined.
Microsoft-specific predefined macros
MSVC supports other predefined macros:
__ARM_ARCHDefined as an integer literal that represents the ARM architecture version. The value is defined as 8 for the Armv8-A architecture. For 8.1 and onwards, the value is scaled for minor versions, such as X.Y, by using the formula X * 100 + Y as defined by the ARM C language extension. For example, for Armv8.1,__ARM_ARCHis 8 * 100 + 1 or 801. To set the ARM architecture version, see/arch (ARM64). This macro was introduced in Visual Studio 2022 version 17.10.__ATOM__Defined as 1 when the/favor:ATOMcompiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX__Defined as 1 when the/arch:AVX,/arch:AVX2,/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler options are set and the compiler target is x86 or x64. Otherwise, undefined.__AVX2__Defined as 1 when the/arch:AVX2,/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX512BW__Defined as 1 when the/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX512CD__Defined as 1 when the/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX512DQ__Defined as 1 when the/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX512F__Defined as 1 when the/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX512VL__Defined as 1 when the/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.__AVX10_VER__Defined as an integer that represents version of AVX10 when the/arch:AVX10.1or/arch:AVX10.2compiler option is set and the compiler target is x86 or x64. Otherwise, undefined._CHAR_UNSIGNEDDefined as 1 if the defaultchartype is unsigned. This value is defined when the/J(Default char type is unsigned) compiler option is set. Otherwise, undefined.__CLR_VERDefined as an integer literal that represents the version of the Common Language Runtime (CLR) used to compile the app. The value is encoded in the formMmmbbbbb, whereMis the major version of the runtime,mmis the minor version of the runtime, andbbbbbis the build number.__CLR_VERis defined if the/clrcompiler option is set. Otherwise, undefined.// clr_ver.cpp // compile with: /clr using namespace System; int main() { Console::WriteLine(__CLR_VER); }_CONTROL_FLOW_GUARDDefined as 1 when the/guard:cf(Enable Control Flow Guard) compiler option is set. Otherwise, undefined.__COUNTER__Expands to an integer literal that starts at 0. The value increments by 1 every time it's used in a source file, or in included headers of the source file.__COUNTER__remembers its state when you use precompiled headers. This macro is always defined.This example uses
__COUNTER__to assign unique identifiers to three different objects of the same type. TheexampleClassconstructor takes an integer as a parameter. Inmain, the application declares three objects of typeexampleClass, using__COUNTER__as the unique identifier parameter:// macro__COUNTER__.cpp // Demonstration of __COUNTER__, assigns unique identifiers to // different objects of the same type. // Compile by using: cl /EHsc /W4 macro__COUNTER__.cpp #include <stdio.h> class exampleClass { int m_nID; public: // initialize object with a read-only unique ID exampleClass(int nID) : m_nID(nID) {} int GetID(void) { return m_nID; } }; int main() { // __COUNTER__ is initially defined as 0 exampleClass e1(__COUNTER__); // On the second reference, __COUNTER__ is now defined as 1 exampleClass e2(__COUNTER__); // __COUNTER__ is now defined as 2 exampleClass e3(__COUNTER__); printf("e1 ID: %i\n", e1.GetID()); printf("e2 ID: %i\n", e2.GetID()); printf("e3 ID: %i\n", e3.GetID()); // Output // ------------------------------ // e1 ID: 0 // e2 ID: 1 // e3 ID: 2 return 0; }__cplusplus_cliDefined as the integer literal value 200406 when compiled as C++ and a/clrcompiler option is set. Otherwise, undefined. When defined,__cplusplus_cliis in effect throughout the translation unit.// cplusplus_cli.cpp // compile by using /clr #include "stdio.h" int main() { #ifdef __cplusplus_cli printf("%d\n", __cplusplus_cli); #else printf("not defined\n"); #endif }__cplusplus_winrtDefined as the integer literal value 201009 when compiled as C++ and the/ZW(Windows Runtime Compilation) compiler option is set. Otherwise, undefined._CPPRTTIDefined as 1 if the/GR(Enable Run-Time Type Information) compiler option is set. Otherwise, undefined._CPPUNWINDDefined as 1 if one or more of the/GX(Enable Exception Handling),/clr(Common Language Runtime Compilation), or/EH(Exception Handling Model) compiler options are set. Otherwise, undefined._DEBUGDefined as 1 when the/LDd,/MDd, or/MTdcompiler option is set. Otherwise, undefined._DLLDefined as 1 when the/MDor/MDd(Multithreaded DLL) compiler option is set. Otherwise, undefined.__FUNCDNAME__Defined as a string literal that contains the decorated name of the enclosing function. The macro is defined only within a function. The__FUNCDNAME__macro isn't expanded if you use the/EPor/Pcompiler option.This example uses the
__FUNCDNAME__,__FUNCSIG__, and__FUNCTION__macros to display function information.// Demonstrates functionality of __FUNCTION__, __FUNCDNAME__, and __FUNCSIG__ macros void exampleFunction() { printf("Function name: %s\n", __FUNCTION__); printf("Decorated function name: %s\n", __FUNCDNAME__); printf("Function signature: %s\n", __FUNCSIG__); // Sample Output // ------------------------------------------------- // Function name: exampleFunction // Decorated function name: ?exampleFunction@@YAXXZ // Function signature: void __cdecl exampleFunction(void) }__FUNCSIG__Defined as a string literal that contains the signature of the enclosing function. The macro is defined only within a function. The__FUNCSIG__macro isn't expanded if you use the/EPor/Pcompiler option. When compiled for a 64-bit target, the calling convention is__cdeclby default. For an example of usage, see the__FUNCDNAME__macro.__FUNCTION__Defined as a string literal that contains the undecorated name of the enclosing function. The macro is defined only within a function. The__FUNCTION__macro isn't expanded if you use the/EPor/Pcompiler option. For an example of usage, see the__FUNCDNAME__macro._INTEGRAL_MAX_BITSDefined as the integer literal value 64, the maximum size (in bits) for a nonvector integral type. This macro is always defined.// integral_max_bits.cpp #include <stdio.h> int main() { printf("%d\n", _INTEGRAL_MAX_BITS); }__INTELLISENSE__Defined as 1 during an IntelliSense compiler pass in the Visual Studio IDE. Otherwise, undefined. You can use this macro to guard code the IntelliSense compiler doesn't understand, or use it to toggle between the build and IntelliSense compiler. For more information, see Troubleshooting Tips for IntelliSense Slowness._ISO_VOLATILEDefined as 1 if the/volatile:isocompiler option is set. Otherwise, undefined._KERNEL_MODEDefined as 1 if the/kernel(Create Kernel Mode Binary) compiler option is set. Otherwise, undefined._M_AMD64Defined as the integer literal value 100 for compilations that target x64 processors or ARM64EC. Otherwise, undefined._M_ARMDefined as the integer literal value 7 for compilations that target ARM processors. Undefined for ARM64, ARM64EC, and other targets._M_ARM_ARMV7VEDefined as 1 when the/arch:ARMv7VEcompiler option is set for compilations that target ARM processors. Otherwise, undefined._M_ARM_FPDefined as an integer literal value that indicates which/archcompiler option was set for ARM processor targets. Otherwise, undefined.A value in the range 30-39 if no
/archARM option was specified, indicating the default architecture for ARM was set (VFPv3).A value in the range 40-49 if
/arch:VFPv4was set.For more information, see
/arch(ARM).
_M_ARM64Defined as 1 for compilations that target ARM64. Otherwise, undefined._M_ARM64ECDefined as 1 for compilations that target ARM64EC. Otherwise, undefined._M_CEEDefined as 001 if any/clr(Common Language Runtime Compilation) compiler option is set. Otherwise, undefined._M_CEE_PUREDeprecated beginning in Visual Studio 2015. Defined as 001 if the/clr:purecompiler option is set. Otherwise, undefined._M_CEE_SAFEDeprecated beginning in Visual Studio 2015. Defined as 001 if the/clr:safecompiler option is set. Otherwise, undefined._M_FP_CONTRACTAvailable beginning in Visual Studio 2022. Defined as 1 if the/fp:contractor/fp:fastcompiler option is set. Otherwise, undefined._M_FP_EXCEPTDefined as 1 if the/fp:exceptor/fp:strictcompiler option is set. Otherwise, undefined._M_FP_FASTDefined as 1 if the/fp:fastcompiler option is set. Otherwise, undefined._M_FP_PRECISEDefined as 1 if the/fp:precisecompiler option is set. Otherwise, undefined._M_FP_STRICTDefined as 1 if the/fp:strictcompiler option is set. Otherwise, undefined._M_IX86Defined as the integer literal value 600 for compilations that target x86 processors. This macro isn't defined for x64 or ARM compilation targets._M_IX86_FPDefined as an integer literal value that indicates the/archcompiler option that was set, or the default. This macro is always defined when the compilation target is an x86 processor. Otherwise, undefined. When defined, the value is:0 if the
/arch:IA32compiler option was set.1 if the
/arch:SSEcompiler option was set.2 if the
/arch:SSE2,/arch:AVX,/arch:AVX2,/arch:AVX512,/arch:AVX10.1, or/arch:AVX10.2compiler option was set. This value is the default if an/archcompiler option wasn't specified. When/arch:AVXis specified, the macro__AVX__is also defined. When/arch:AVX2is specified, both__AVX__and__AVX2__are also defined. When/arch:AVX512is specified,__AVX__,__AVX2__,__AVX512BW__,__AVX512CD__,__AVX512DQ__,__AVX512F__, and__AVX512VL__are also defined. When/arch:AVX10.1or/arch:AVX10.2is specified,__AVX__,__AVX2__,__AVX512BW__,__AVX512CD__,__AVX512DQ__,__AVX512F__,__AVX512VL__and__AVX10_VER__are also defined.For more information, see
/arch(x86).
_M_X64Defined as the integer literal value 100 for compilations that target x64 processors or ARM64EC. Otherwise, undefined._MANAGEDDefined as 1 when the/clrcompiler option is set. Otherwise, undefined._MSC_BUILDDefined as an integer literal that contains the revision number element of the compiler's version number. The revision number is the last element of the period-delimited version number. For example, if the version number of the Microsoft C/C++ compiler is 15.00.20706.01, the_MSC_BUILDmacro is 1. This macro is always defined._MSC_EXTENSIONSDefined as 1 if the on-by-default/Ze(Enable Language Extensions) compiler option is set. Otherwise, undefined._MSC_FULL_VERDefined as an integer literal that encodes the major, minor, and build number elements of the compiler's version number. The major number is the first element of the period-delimited version number, the minor number is the second element, and the build number is the third element.For example, if the Microsoft C/C++ compiler version is 19.39.33519,
_MSC_FULL_VERis 193933519. Entercl /?at the command line to view the compiler's version number. This macro is always defined. For more information about compiler versioning, see C++ compiler versioning and specifically Service releases starting with Visual Studio 2017 for more information about Visual Studio 2019 16.8, 16.9, 16.10 and 16.11, which require_MSC_FULL_VERto tell them apart._MSC_VERDefined as an integer literal that encodes the major and minor number elements of the compiler's version number. The major number is the first element of the period-delimited version number and the minor number is the second element. For example, if the version number of the Microsoft C/C++ compiler is 17.00.51106.1, the value of_MSC_VERis 1700. Entercl /?at the command line to view the compiler's version number. This macro is always defined.To test for compiler releases or updates in a given version of Visual Studio or later, use the
>=operator. You can use it in a conditional directive to compare_MSC_VERagainst that known version. If you have several mutually exclusive versions to compare, order your comparisons in descending order of version number. For example, this code checks for compilers released in Visual Studio 2017 and later. Next, it checks for compilers released in or after Visual Studio 2015. Then it checks for all compilers released before Visual Studio 2015:#if _MSC_VER >= 1910 // . . . #elif _MSC_VER >= 1900 // . . . #else // . . . #endifFor more information about Visual Studio 2019 16.8 and 16.9, and 16.10 and 16.11, which share the same major and minor versions (and so have the same value for
_MSC_VER), see Service releases starting with Visual Studio 2017.For more information about the history of compiler versioning, and compiler version numbers and the Visual Studio versions they correspond to, see C++ compiler versioning. Also, Visual C++ Compiler Version on the Microsoft C++ team blog.
_MSVC_LANGDefined as an integer literal that specifies the C++ language standard targeted by the compiler. Only code compiled as C++ sets it. The macro is the integer literal value201402Lby default, or when the/std:c++14compiler option is specified. The macro is set to201703Lif the/std:c++17compiler option is specified. The macro is set to202002Lif the/std:c++20compiler option is specified. It's set to a higher, unspecified value when the/std:c++latestoption is specified. Otherwise, the macro is undefined. The_MSVC_LANGmacro and/std(Specify language standard version) compiler options are available beginning in Visual Studio 2015 Update 3.__MSVC_RUNTIME_CHECKSDefined as 1 when one of the/RTCcompiler options is set. Otherwise, undefined._MSVC_TRADITIONAL:- Available beginning with Visual Studio 2017 version 15.8: Defined as 0 when the preprocessor conformance mode
/experimental:preprocessorcompiler option is set. Defined as 1 by default, or when the/experimental:preprocessor-compiler option is set, to indicate the traditional preprocessor is in use. - Available beginning with Visual Studio 2019 version 16.5: Defined as 0 when the preprocessor conformance mode
/Zc:preprocessorcompiler option is set. Defined as 1 by default, or when the/Zc:preprocessor-compiler option is set, to indicate the traditional preprocessor is in use (essentially,/Zc:preprocessorreplaces the deprecated/experimental:preprocessor).
#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL // Logic using the traditional preprocessor #else // Logic using cross-platform compatible preprocessor #endif- Available beginning with Visual Studio 2017 version 15.8: Defined as 0 when the preprocessor conformance mode
_MTDefined as 1 when/MDor/MDd(Multithreaded DLL) or/MTor/MTd(Multithreaded) is specified. Otherwise, undefined._NATIVE_WCHAR_T_DEFINEDDefined as 1 when the/Zc:wchar_tcompiler option is set. Otherwise, undefined._OPENMPDefined as integer literal 200203, if the/openmp(Enable OpenMP 2.0 Support) compiler option is set. This value represents the date of the OpenMP specification implemented by MSVC. Otherwise, undefined.// _OPENMP_dir.cpp // compile with: /openmp #include <stdio.h> int main() { printf("%d\n", _OPENMP); }_PREFAST_Defined as 1 when the/analyzecompiler option is set. Otherwise, undefined.__SANITIZE_ADDRESS__Available beginning with Visual Studio 2019 version 16.9. Defined as 1 when the/fsanitize=addresscompiler option is set. Otherwise, undefined.__TIMESTAMP__Defined as a string literal that contains the date and time of the last modification of the current source file, in the abbreviated, constant length form returned by the CRTasctimefunction, for example,Fri 19 Aug 13:32:58 2016. This macro is always defined._VC_NODEFAULTLIBDefined as 1 when the/Zl(Omit Default Library Name) compiler option is set. Otherwise, undefined._WCHAR_T_DEFINEDDefined as 1 when the default/Zc:wchar_tcompiler option is set. The_WCHAR_T_DEFINEDmacro is defined but has no value if the/Zc:wchar_t-compiler option is set, andwchar_tis defined in a system header file included in your project. Otherwise, undefined._WIN32Defined as 1 when the compilation target is 32-bit ARM, 64-bit ARM, x86, x64, or ARM64EC. Otherwise, undefined._WIN64Defined as 1 when the compilation target is 64-bit ARM, x64, or ARM64EC. Otherwise, undefined._WINRT_DLLDefined as 1 when compiled as C++ and both/ZW(Windows Runtime Compilation) and/LDor/LDdcompiler options are set. Otherwise, undefined.
No preprocessor macros that identify the ATL or MFC library version are predefined by the compiler. ATL and MFC library headers define these version macros internally. They're undefined in preprocessor directives made before the required header is included.
_ATL_VERDefined in<atldef.h>as an integer literal that encodes the ATL version number._MFC_VERDefined in<afxver_.h>as an integer literal that encodes the MFC version number.
See also
Macros (C/C++)
Preprocessor operators
Preprocessor directives