Why can't the C compiler make comparisons / unsigned comparisons in an intuitive way

By "intuitive" I mean given

int a = -1;
unsigned int b = 3;

expression (a < b)must be evaluated at 1.

There are several questions that Stackoverflow already asks why, in a particular case, the C compiler complains about signature / unsigned matching. The answers come down to whole conversion rules and the like. However, there seems to be no justification for why the compiler should be so dumb when comparing integers and single integers. Using the declarations above why an expression like

(a < b)

not automatically replaced by

(a < 0 || (unsigned int)a < b)

if there is no single machine instruction to do it right?

" , - ". , libc (, sprintf() int , send() ssize_t ..).

, , , , ( (d - '0' < 10U)) C (((unsigned int)(d - '0') < 10U)). , , .

, , , ( , ). , ? , , ?

+5
4

- , C , . :

if (d-'0'<10U)  // false if d is not a digit

ASCII .

, , :

, / C/++?

+6

, C ( ++), , . , . , , . , , , , , .

/ , , , .

+1

. , ( , ) . , . , int , , no-op , - , .

, , , . -

C . - , .

( ) , , . , , , - .

+1

, , .

- .

-2147483648 2147483648 (+ - ), 0 4294967296.

, , , MSB .

:

-1 3 000 000 000. ? , , ... , -1 , " unsigned" ( ), -1 . (4294967296).

, , , .

This is why the compiler generates this warning. While the actual case of error is quite rare, it still CAN. And this is what the compiler warns you that something unexpected can happen when comparing two different significant integers.

0
source

All Articles