Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1 KB

compiler-warning-level-4-c4389.md

File metadata and controls

49 lines (36 loc) · 1 KB
title description ms.date f1_keywords helpviewer_keywords
Compiler Warning (level 4) C4389
Microsoft C/C++ compiler warning C4389, its causes and resolution.
10/16/2020
c4389
C4389

Compiler Warning (level 4) C4389

'equality-operator' : signed/unsigned mismatch

An == or != operation involved signed and unsigned variables. This could result in a loss of data.

Remarks

One way to fix this warning is if you cast one of the two types when you compare signed and unsigned types.

Example

The following sample generates C4389:

// C4389.cpp
// compile with: cl /EHsc /W4 C4389.cpp

int main()
{
   int a = 9;
   unsigned int b = 10;
   int result = 0;

   if (a == b)   // C4389
      result = 1;
   else
      result = 2;

   if (unsigned(a) == b) // OK
      result = 3;
   else
      result = 4;

   return result;
}

See also

Compiler Warning C4018
Compiler Warning (Level 4) C4388