Click here to Skip to main content
15,886,067 members
Articles / DevOps
Reference

Visual C/C++ Macro and Compiler Switch Cheat Sheet

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
4 Apr 2019CPOL14 min read 13.1K   193   8   1
Here I present a cheat sheet that I assembled for my own use, in the hope that others may as well find it useful.

Introduction

Recently, in the course of researching a coding issue related to a straight C program that I was developing, I noticed some Microsoft-specific predefined C/C++ preprocessor macros that I hadn't noticed before. Seeing these macros gave me an idea for a better approach to another problem that I had already solved by another method that was quite a bit less elegant.

Background

Like many of the lists and charts published by Microsoft, the format of the Predefined Macros list leaves a lot to be desired. Since I seem to be needing quick access to more of these switches, I decided that it was worth spending an hour or two to format it in a way that seems more useful to me, because it puts the compiler switches, macro values, and references to related pages of the compiler documentation into separate columns, so that they are easy to find.

Using the code

The following table contains the same information that appears in the Microsoft article, but I think this table is easier to read and use as a cheat sheet.

  1. The macros are shown alphabetically by macro name, without regard to whether they are standard or Microsoft-specific; use the Status column to determine which are standard and which are MS only.
  2. The Range column lists the single value or range of values that may be assigned to the macro. For the most part, the everyday macros are either defined with a value of 1 or are undefined.
  3. The CL Switch column lists the pertinent Visual C++ command line compiler switches; these are the switches mentioned in the adjacent Details column.
Symbol Status Range CL Switch Details Reference
_ATL_VER Microsoft     Defined in <atldef.h> as an integer literal that encodes the ATL version number. atldef.h
_MFCVER Microsoft     |Defined in <afxver.h> as an integer literal that encodes the MFC version number. afxver_.h
ATOM Microsoft 1 /favor:ATOM Defined as 1 when the /favor:ATOM compiler option is set and the compiler target is x86 or x64. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/favor-optimize-for-architecture-specifics?view=vs-2017
AVX Microsoft 1 /arch:AVX OR /arch:AVX2 Defined as 1 when the /arch:AVX or /arch:AVX2 compiler options are set and the compiler target is x86 or x64. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/arch-x86?view=vs-2017
AVX2 Microsoft 1 /arch:AVX2 Defined as 1 when the /arch:AVX2 compiler option is set and the compiler target is x86 or x64. Otherwise, undefined  
_CHAR_UNSIGNED Microsoft 1 /J Defined as 1 if the default char type is unsigned. This is set when the /J (Default char Type Is unsigned) compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/j-default-char-type-is-unsigned?view=vs-2017
__CLR_VER Microsoft     Defined as an integer literal that represents the version of the common language runtime used when the application was compiled. The value is encoded in the form Mmmbbbbb, where M is the major version of the runtime, mm is the minor version of the runtime, and bbbbb is the build number. __CLR_VER is defined if the /clr compiler option is set. Otherwise, undefined.  
_CONTROL_FLOW_GUARD Microsoft 1 /guard:cf Defined as 1 when the /guard:cf (Enable Control Flow Guard) compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-control-flow-guard?view=vs-2017
COUNTER Microsoft 0   Expands to an integer literal that starts at 0 and is incremented by 1 every time it is used in a source file or included headers of the source file. COUNTER remembers its state when you use precompiled headers. This macro is always defined. See the source document for a good example.  
__cplusplus Standard   compiled as C++ Defined as an integer literal value when the translation unit is compiled as C++. Otherwise, undefined.  
__cplusplus_cli Microsoft 200406 /clr AND compiled as C++ Defined as the integer literal value 200406 when compiled as C++ and a /clr compiler option is set. Otherwise, undefined. When defined, __cplusplus_cli is in effect throughout the translation unit.  
__cplusplus_winrt Microsoft 201009 /ZW Defined as the integer literal value 201009 when compiled as C++ and the /ZW (Windows Runtime Compilation) compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/zw-windows-runtime-compilation?view=vs-2017
_CPPRTTI Microsoft 1 /GR Defined as 1 if the /GR (Enable Run-Time Type Information) compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/gr-enable-run-time-type-information?view=vs-2017
_CPPUNWIND Microsoft 1 /GX OR /clr OR /EH Defined 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. https://docs.microsoft.com/en-us/cpp/build/reference/gx-enable-exception-handling?view=vs-2017
          https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2017
DATE Standard     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 in dates generated by the C Runtime Library asctime function. The first character of date dd is a space if the value is less than 10. This macro is always defined. https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/asctime-wasctime?view=vs-2017
_DEBUG Microsoft 1 /LDd OR /MDd OR /MTd Defined as 1 when the /LDd, /MDd, or /MTd compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017
_DLL Microsoft 1 /MD OR /MDd Defined as 1 when the /MD or /MDd (Multithreaded DLL) compiler option is set. Otherwise, undefined.  
FILE Standard   /FC to elicit full paths 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 https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2017
_FUNCDNAME Microsoft     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 is not expanded if you use the /EP or /P compiler option. https://docs.microsoft.com/en-us/cpp/build/reference/decorated-names?view=vs-2017
FUNCSIG Microsoft     Defined as a string literal that contains the signature of the enclosing function. The macro is defined only within a function. The FUNCSIG macro is not expanded if you use the /EP or /P compiler option. When compiled for a 64-bit target, the calling convention is cdecl by default. For an example of usage, see the FUNCDNAME__ macro. https://docs.microsoft.com/en-us/cpp/build/reference/ep-preprocess-to-stdout-without-hash-line-directives?view=vs-2017

https://docs.microsoft.com/en-us/cpp/build/reference/p-preprocess-to-a-file?view=vs-2017
FUNCTION Microsoft     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 is not expanded if you use the /EP or /P compiler option. For an example of usage, see the FUNCDNAME macro.  
_INTEGRAL_MAX_BITS Microsoft 64   Defined as the integer literal value 64, the maximum size (in bits) for a non-vector integral type. This macro is always defined.  
INTELLISENSE Microsoft 1   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 does not understand, or use it to toggle between the build and IntelliSense compiler. For more information, see Troubleshooting Tips for IntelliSense Slowness. https://devblogs.microsoft.com/cppblog/troubleshooting-tips-for-intellisense-slowness/
_ISO_VOLATILE Microsoft 1 /volatile:iso Defined as 1 if the /volatile:iso compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/volatile-volatile-keyword-interpretation?view=vs-2017
_KERNEL_MOD Microsoft 1 /kernel Defined as 1 if the /kernel (Create Kernel Mode Binary) compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=vs-2017
_M_AMD64 Microsoft 100   Defined as the integer literal value 100 for compilations that target x64 processors. Otherwise, undefined.  
_M_ARM Microsoft 7   Defined as the integer literal value 7 for compilations that target ARM processors. Otherwise, undefined.  
_M_ARM_ARMV7VE Microsoft 1 /arch:ARMv7VE Defined as 1 when the /arch:ARMv7VE compiler option is set for compilations that target ARM processors. Otherwise, undefined https://docs.microsoft.com/en-us/cpp/build/reference/arch-arm?view=vs-2017
M_ARM_FP Microsoft     Defined as an integer literal value that indicates which /arch compiler option was set, if the compilation target is an ARM processor. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/arch-arm?view=vs-2017
  Microsoft 30-39 /arch:ARM In the range 30-39 if no /arch ARM option was specified, indicating the default architecture for ARM was set (VFPv3).  
  Microsoft 40-49 /arch:VFPv4 In the range 40-49 if /arch:VFPv4 was set.  
_M_ARM64 Microsoft 1   Defined as 1 for compilations that target 64-bit ARM processors. Otherwise, undefined  
_M_CEE Microsoft 001 any /clr compiler option Defined as 001 if any /clr (Common Language Runtime Compilation) compiler option is set. Otherwise, undefined  
_M_CEE_PURE Microsoft 001 /clr:pure Deprecated beginning in Visual Studio 2015. Defined as 001 if the /clr:pure compiler option is set. Otherwise, undefined.  
_M_CEE_SAFE Microsoft 001 /clr:safe Deprecated beginning in Visual Studio 2015. Defined as 001 if the /clr:safe compiler option is set. Otherwise, undefined  
_M_FP_EXCEPT Microsoft 1 /fp:except OR /fp:stric Defined as 1 if the /fp:except or /fp:strict compiler option is set. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior?view=vs-2017
_M_FP_FAST Microsoft 1 /fp:fast Defined as 1 if the /fp:fast compiler option is set. Otherwise, undefined.  
_M_FP_PRECISE Microsoft 1 /fp:precise Defined as 1 if the /fp:precise compiler option is set. Otherwise, undefined.  
_M_FP_STRICT Microsoft 1 /fp:strict Defined as 1 if the /fp:strict compiler option is set. Otherwise, undefined.  
_M_IX86 Microsoft 600   Defined as the integer literal value 600 for compilations that target x86 processors. This macro is not defined for x64 or ARM compilation targets  
_M_IX86_FP Microsoft   /arch Defined as an integer literal value that indicates the /arch compiler 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 https://docs.microsoft.com/en-us/cpp/build/reference/arch-arm?view=vs-2017
  Microsoft 0 /arch:IA32 the /arch:IA32 compiler option was set.  
  Microsoft 1 /arch:SSE the /arch:SSE compiler option was set.  
  Microsoft 2 /arch:SSE2 OR /arch:AVX OR /arch:AVX2 the /arch:SSE2, /arch:AVX or /arch:AVX2 compiler option was set. This value is the default if an /arch compiler option was not specified. When /arch:AVX is specified, the macro AVX is also defined.  
  Microsoft   /arch:AVX2 When /arch:AVX2 is specified, both AVX and AVX2 are also defined.  
LINE Standard     Defined as the integer line number in the current source file. The value of the LINE macro can be changed by using a #line directive. This macro is always defined.  
_M_X64 Microsoft 100   Defined as the integer literal value 100 for compilations that target x64 processors. Otherwise, undefined.  
_MANAGED Microsoft 1 /clr Defined as 1 when the /clr compiler option is set. Otherwise, undefined.  
_MSC_BUILD Microsoft     Defined as an integer literal that contains the revision number element of the compiler's version number. The revision number is the fourth element of the period-delimited version number. For example, if the version number of the Visual C++ compiler is 15.00.20706.01, the _MSC_BUILD macro evaluates to 1. This macro is always defined.  
_MSC_EXTENSIONS Microsoft 1 /Ze Defined as 1 if the /Ze (Enable Language Extensions) compiler option is set, which is the default. Otherwise, undefined. https://docs.microsoft.com/en-us/cpp/build/reference/za-ze-disable-language-extensions?view=vs-2017
_MSC_FULL_VER Microsoft     Defined 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 version number of the Visual C++ compiler is 15.00.20706.01, the _MSC_FULL_VER macro evaluates to 150020706. Enter cl /? at the command line to view the compiler's version number. This macro is always defined.  
_MSC_VER Microsoft     Defined 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 Visual C++ compiler is 17.00.51106.1, the _MSC_VER macro evaluates to 1700. Enter cl /? at the command line to view the compiler's version number. This macro is always defined https://devblogs.microsoft.com/cppblog/visual-c-compiler-version/
  Microsoft 1200   Visual Studio 6.0  
  Microsoft 1300   Visual Studio .NET 2002 (7.0)  
  Microsoft 1310   Visual Studio .NET 2003 (7.1)  
  Microsoft 1400   Visual Studio 2005 (8.0)  
  Microsoft 1500   Visual Studio 2008 (9.0)  
  Microsoft 1600   Visual Studio 2010 (10.0)  
  Microsoft 1700   Visual Studio 2012 (11.0)  
  Microsoft 1800   Visual Studio 2013 (12.0)  
  Microsoft 1900   Visual Studio 2015 (14.0)  
  Microsoft 1910   Visual Studio 2017 RTW (15.0)  
  Microsoft 1911   Visual Studio 2017 version 15.3  
  Microsoft 1912   Visual Studio 2017 version 15.5  
  Microsoft 1913   Visual Studio 2017 version 15.6  
  Microsoft 1914   Visual Studio 2017 version 15.7  
  Microsoft 1915   Visual Studio 2017 version 15.8  
  Microsoft 1916   Visual Studio 2017 version 15.9  
_MSVC_LANG Microsoft     Defined as an integer literal that specifies the C++ language standard targeted by the compiler.  
  Microsoft 201402L   When compiled as C++, the macro is the integer literal value 201402L.  
  Microsoft 201703L   if the /std:c++14 compiler option is set, or by default; it is set to 201703L.  
  Microsoft     If the /std:c++17 compiler option is set; and it is set to a higher, unspecified value when the /std:c++latest.  
  Microsoft     Otherwise, the macro is undefined.  
__MSVC_RUNTIME_CHECKS Microsoft 1   Defined as 1 when one of the /RTC compiler options is set. Otherwise, undefined.  
_MT Microsoft 1   Defined as 1 when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified. Otherwise, undefined  
_NATIVE_WCHAR_T_DEFINED Microsoft 1   Defined as 1 when the /Zc:wchar_t compiler option is set. Otherwise, undefined.  
_OPENMP Microsoft 200203 /openmp Defined as integer literal 200203, representing the date of the OpenMP specification implemented by Visual C++, if the /openmp (Enable OpenMP 2.0 Support) compiler option is set.  
PREFAST Microsoft 1 /analyze Defined as 1 when the /analyze compiler option is set. Otherwise, undefined.  
STDC Standard 1 /Za AND compiled as C Defined as 1 only when compiled as C and if the /Za compiler option is specified. Otherwise, undefined.  
__STDC_HOSTED__ Standard 1   Defined as 1 if the implementation is a hosted implementation, one that supports the entire required standard library. Otherwise, defined as 0.  
__STDCPP_THREADS__ Standard 1   Defined as 1 if and only if a program can have more than one thread of execution, and compiled as C++. Otherwise, undefined  
TIME Standard     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 C Runtime Library asctime function. This macro is always defined.  
__TIMESTAMP_ Microsoft     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 C Runtime Library asctime function, for example, Fri 19 Aug 13:32:58 2016. This macro is always defined.  
_VC_NODEFAULTLIB Microsoft 1 /Zl Defined as 1 when the /Zl (Omit Default Library Name) compiler option is set. Otherwise, undefined.  
_WCHAR_T_DEFINED Microsoft 1 /Zc:wchar_t Defined as 1 when the default /Zc:wchar_t compiler option is set. The _WCHAR_T_DEFINED macro is defined but has no value if the /Zc:wchar_t- compiler option is set, and wchar_t is defined in a system header file included in your project. Otherwise, undefined.  
_WIN32 Microsoft 1   Defined as 1 when the compilation target is 32-bit ARM, 64-bit ARM, x86, or x64. Otherwise, undefined.  
_WIN64 Microsoft 1   Defined as 1 when the compilation target is 64-bit ARM or x64. Otherwise, undefined.  
_WINRT_DLL Microsoft 1 /ZW AND (/LD OR /LDd) AND compiled as C++ Defined as 1 when compiled as C++ and both /ZW (Windows Runtime Compilation) and /LD or /LDd compiler options are set. Otherwise, undefined.  
 

Points of Interest

I constructed the table from the Excel worksheet in the archive that accompanies this article. From there, I copied the worksheet into a text editor, saved the file as Markdown, then use Carsten Brandt's A super fast, highly extensible markdown parser for PHP to generate Git Flavored Markdown. Though I had to fix a few parse errors, it took only a few more minutes to have a presentable table that could be pasted into the Code Project article editor. Given that the table had some quirks, such as a fair number of blank cells, the parse errors didn't bother me. The resultang table was much leaner than anything I could have realized directly from Excel.

ToDo

The table could stand one more column, to display the MSBuild property that corresponds to each CL switch.

History

Thursday, 04 April 2019 is the initial publication date.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I deliver robust, clean, adaptable, future-ready applications that are properly documented for users and maintainers. I have deep knowledge in multiple technologies and broad familiarity with computer and software technologies of yesterday, today, and tomorrow.

While it isn't perceived as sexy, my focus has always been the back end of the application stack, where data arrives from a multitude of sources, and is converted into reports that express my interpretation of The Fundamental Principle of Tabular Reporting, and are the most visible aspect of the system to senior executives who approve the projects and sign the checks.

While I can design a front end, I prefer to work at the back end, getting data into the system from outside sources, such as other computers, electronic sensors, and so forth, and getting it out of the system, as reports to IDENTIFY and SOLVE problems.

When presented with a problem, I focus on identifying and solving the root problem for the long term.

Specialties: Design: Relational data base design, focusing on reporting; organization and presentation of large document collections such as MSDS libraries

Development: Powerful, imaginative utility programs and scripts for automated systems management and maintenance

Industries: Property management, Employee Health and Safety, Services

Languages: C#, C++, C, Python, VBA, Visual Basic, Perl, WinBatch, SQL, XML, HTML, Javascript

Outside Interests: Great music (mostly, but by no means limited to, classical), viewing and photographing sunsets and clouds, traveling by car on small country roads, attending museum exhibits (fine art, history, science, technology), long walks, especially where there is little or no motor traffic, reading, especially nonfiction and thoughtfully written, thought provoking science fiction

Comments and Discussions

 
Generalvery handy Pin
Southmountain28-Feb-20 4:46
Southmountain28-Feb-20 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.