If I use only unsigned types in ternary operator condition, will these unsigned variables be automatically converted to signed types?
Simple example:
unsigned int prevTickSeconds = 48;
unsigned int currentTickSeconds = 5;
unsigned int secondsLeft = (currentTickSeconds - prevTickSeconds ) ?
currentTickSeconds - prevTickSeconds :
60 - prevTickSeconds + currentTickSeconds;
Will this construction work properly when (currentTickSeconds > prevTickSeconds) as shown in this example? Will type conversion performed automatically for condition in ternary operator, or not?
No, there’s no such conversion, as all types are
unsigned intand there will be “underflow”.NOTE:
will be executed if and only if
currentTickSeconds - prevTickSecondsis0.