Consider this code:
LARGE_INTEGER l;
size_t s;
if (s < l.QuadPart) return 1;
return 0;
When this is compiled under x64 it generates the C4018 signed/unsigned mismatch compiler warning (Ignore the uninitialized local variable warning).
The warning is fine, since QuadPart is LONGLONG which is signed and size_t is unsigned.
But when I compile this under 32-bit there is no warning? How come? Under 32-bit LONGLONG is still signed and size_t is unsigned.
On 32-bit
LONGLONGis equivalent tosigned __int64andsize_tis equivalent tounsigned int.unsigned inthas range that completely fits intosigned __int64range, so the compiler widens (does integer promotion)size_ttosigned __int64before the comparison and there’s no warning.On 64-bit
LONGLONGis again equivalent tosigned __int64butsize_tis equivalent tounsigned __int64, so nowsize_tno longer fits intoLONGLONGand the compiler can’t perform any kind of promotion automatically, hence the warning.