User and Reference Guide for the Intel® C++ Compiler 14.0

Compilation and Execution Differences

While the Intel® C++ Compiler is compatible with the Microsoft Visual C++* compiler, some differences can prevent successful compilation. Also there can be some incompatible generated-code behavior of some source files with the Intel C++ Compiler. In most cases, a modification of the user source file enables successful compilation with both the Intel C++ Compiler and the Microsoft Visual C++ compiler. The differences between the compilers are listed as follows:

Preprocessor Macro Expansion

The Intel C++ Compiler differs from the Microsoft Visual C++ compiler in the way it expands preprocessor macros that are used within #include directives. In some case the code passes a macro as a parameter to another macro that uses the token-concatenation operator. In such a case, the macro that is used as a parameter is not expanded before concatenation. This is demonstrated in the following example:

#define D var
#define Decl(d) int my ## d;
Decl(D)

Both compilers would preprocess the preceding source and produce the following code:

int myD;

When a similar macro is used in a #include directive, the Intel C++ Compiler behaves similarly to the preceding example. However, the Microsoft Visual C++ compiler performs an extra preprocessing scan through the #include directive to produce different results. In the following example, the D and F macros, when used in the #include directive, are not expanded by the Intel C++ Compiler.

#define D sys
#define F stat.h
#define INC(d,f) < ## d ## / ## f ## >
#include INC(D,F)

Visual C++ compiler interpretation:

#include <sys/stat.h>

Intel C++ Compiler interpretation:

#include <D/F>

The Intel C++ Compiler issues an error for this code when it fails to find the file called D/F. The Microsoft Visual C++ compiler expands the D and F macros and accepts this code. The following alternative code achieves the same result, but it works with both the Intel C++ Compiler and the Microsoft Visual C++ compiler:

#define D sys
#define F stat.h
#define CAT5(a,b,c,d,e) a ## b ## c ## d ## e
#define INC(d,f) CAT5(<,d,/,f,>)
#include INC(D,F)

Evaluation of Left Shift Operations

The Intel C++ Compiler differs from the Microsoft Visual C++ compiler in the evaluation of left shift operations where the right operand, or shift count, is equal to or greater than the size of the left operand expressed in bits. The ANSI C standard states that the behavior of such left-shift operations is undefined, meaning a program should not expect a certain behavior from these operations. This difference is only evident when both operands of the shift operation are constants. The following example illustrates this difference between the Intel C++ Compiler and the Microsoft Visual C++ compiler:

int x;
int y = 1; //set y=1
void func()
{
  x = 1 << 32;
  // Visual C++ Compiler generates code to set x=0
  // Intel C++ Compiler generates code to set x=1
  
  y = y << 32;
  // Visual C++ Compiler generates code to set y=1
  // Intel C++ Compiler generates code to set y=1
}

Inline Assembly Target Labels (IA-32 Architecture Only)

For compilations targeted for IA-32 architecture, inline assembly target labels of goto statements are case sensitive. The Microsoft Visual C++ compiler treats these labels in a case insensitive manner. For example, the Intel C++ Compiler issues an error when compiling the following code:

int func(int x)
{
   goto LAB2;
   // error: label "LAB2" was referenced but not defined
   __asm lab2: mov x, 1
   return x;
}

However, the Microsoft Visual C++ compiler accepts the preceding code. As a work-around for the Intel C++ Compiler, when a goto statement refers to a label defined in inline assembly, you must match the label reference with the label definition in both name and case.


Submit feedback on this help topic