TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  CON#007

Synopsis:Do not convert implicitly from a boolean type to a non-boolean type, and vice versa.
Language:C++
Severity Level:3
Category:Conversions


Description:

Example:

int i = 5, j = 4, k = 3, l = 2; 
int* i_ptr = &i;

bool b = (i > j);              // right 
int a = (i > j);                 // wrong: implicit conversion from bool to int 
int a = ((i > j) + (k > l)) // wrong: implicit conversion from bool to int
if (i_ptr)                         // wrong: implicit conversion from int* to bool
if (i_ptr != NULL)         // right: explicit comparison to null pointer