Petruza Petruza - 9 days ago 5
C++ Question

Can I assume (bool)true == (int)1 for any C++ compiler?

Can I assume

(bool)true == (int)1
for any C++ compiler ?

Answer

Yes. The casts are redundant. In your expression:

true == 1

Integral promotion applies and the bool value will be promoted to an int and this promotion must yield 1.

Reference: 4.7 [conv.integral] / 4: If the source type is bool... true is converted to one.

Comments