Export (0) Print
Expand All
Expand Minimize
2 out of 3 rated this helpful - Rate this topic

Compiler Warning (level 4) C4127

conditional expression is constant

The controlling expression of an if statement or while loop evaluates to a constant. If the controlling expression of a while loop is a constant because the loop will exit in the middle, consider replacing the while loop with a for loop. You can omit the initialization, termination test and loop increment of a for loop, which causes the loop to be infinite (like while(1)) and you can exit the loop from the body of the for statement.

The following sample generates C4127:

// C4127.cpp
// compile with: /W4
#include <stdio.h>
int main() {
   if (1 == 1) {}   // C4127
   while (1) { break; }   // C4127

   // OK
   for ( ; ; ) {
      printf("test\n");
      break;
   }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.