Consider this code:
#define SZIE 1024
printf("%\zu",SZIE<-1?1:0);
It will print '0'. This confuses me.
In my view, the signed number -1 shoulkd be converted to SIZE_MAX.
The expression 1024 < SIZE_MAX is true, so I think "1" should be printed, but no.
I tried converting explicitly:
printf("%zu",SIZE<(size_t)-1?1:0);
It prints "1", which seems correct.
You defined a macro
SZIE(I think you meanSIZE) for the integer constant1024of the typeint.So
1024is not less than-1.Moreover as the operands have the type
intthen and the result of the conditional operator has also the typeintand you need to use the conversion specifierdinstead ofzuin the call of printf. And it seems there is a typo\zin the format stringThat is you need to write
If you need to get the expected result you can write for example
Or it would be enough to introduce a constant of the type
unsigned intlikeand write
In this case due to the usual arithmetic conversions the expression
-1having the typeintwill be converted to the typeunsigned intproducing a big unsigned value.Pay attention to that independent of the condition expression of the conditional operator its result in any case has the type
intbecause the second and the third operands have the typeint. And the condition expression itself has the typeintand yields either0or1.