Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a preprocessor define that is defined if the compiler is MSVC?

So I can do something like

#ifdef MSVC //do compiler specific code here #endif 
like image 982
Avery3R Avatar asked May 01 '11 18:05

Avery3R


People also ask

Is MSVC a compiler?

The Microsoft C/C++ compiler (MSVC) uses a basic rule to determine which language to use when it compiles your code. By default, the MSVC compiler treats all files that end in . c as C source code, and all files that end in .

What compiler does MSVC use?

Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.

Is compiler a preprocessor?

The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it. These transformations are lexical, meaning that the output of the preprocessor is still text.

What are preprocessor definitions?

In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.


1 Answers

It's _MSC_VER. More info at MSDN and at predef.

But, be aware that some other compilers may also define it, e.g. Intel's C++ Compiler for Windows also defines _MSC_VER. If this is a concern, use #if _MSC_VER && !__INTEL_COMPILER.

like image 186
Alexey Kukanov Avatar answered Sep 17 '22 12:09

Alexey Kukanov