This documentation is archived and is not being maintained.

Compiler Error C3018

Error Message

'var1' : OpenMP 'for' test or increment must use index variable 'var2'

A for loop in an OpenMP statement must use the same variable for its test and increment as it uses for its index.

The following sample generates C3018:

// C3018.cpp
// compile with: /openmp
int main()
{
   int i = 0, j = 5;

   #pragma omp parallel
   {
      #pragma omp for
      for (i = 0; j < 10; ++i)   // C3018
      // try the the following line instead
      // for (i = 0; i < 10; ++i)
         j *= 2;

      #pragma omp for
      for (i = 0; i < 10; j = j + i)   // C3018
      // try the the following line instead
      // for (i = 0; i < 10; i = j + i)
         j *= 2;
   }
}
Show: