Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 3) C4018

'expression' : signed/unsigned mismatch

Comparing a signed and unsigned number required the compiler to convert the signed value to unsigned.

Possible solution

  • Cast one of the two types when testing signed and unsigned types for equality (= =) or inequality (!=).

The following sample generates C4018:

// C4018.cpp
// compile with: /W3
int  main()
{
   unsigned int uc = 0;
   int c = 0;
   // try..
   // unsigned int c = 0;
   if (uc < c)   // C4018 (also for >, >=, and <=)
      uc = 0;
   if (uc == c)
      uc = 0;
   return 0;
}
Show:
© 2014 Microsoft