24 Nov
2018
24 Nov
'18
12:55 p.m.
Am 23.11.2018 um 20:58 schrieb Emil Dotchevski via Boost:
unsigned f();
void g( int x ) { if( x < f() ) //warning C4018: '<': signed/unsigned mismatch { .... } }
The only problem that I can see here is the fact, that this is flagged as a warning rather than an error. I know, this is technically correct but you simply cannot compare values from different value domains without preconditions. Not stating the preconditions is an error. If you state them and assure that the actual values of both 'x' and 'f()' can be equally represented as 'int' oder 'unsigned' then and only then the comparison is correct and a explicit cast to either type is a valid one. Ciao Dani