[tz] Compiler warning in tzcode2016g about SIZE_MAX being wider than int

Clive D.W. Feather clive at davros.org
Sat Oct 22 16:17:47 UTC 2016


Tom Lane said:
> I suppose that clang's check must be calibrated to allow stuffing an
> unsigned value into a signed value of the same width, just not narrower
> widths.

Three things to note about this sort of stuff in C:

(1) The range of values of an unsigned type has to include all the
non-negative values of the corresponding signed type, but doesn't have to
be any bigger. In other words, INT_MAX == UINT_MAX is allowed.

(2) Just because two types with the same signedness have the same size as
given by sizeof, they don't have to have the same range of values. So even
if sizeof(int) == sizeof(long), INT_MAX != LONG_MAX is still allowed.

(3) Just because two types have the same size, signedness, and range of
values, doesn't mean they have the same representation. For example, int
could be big-endian and long little-endian.

-- 
Clive D.W. Feather          | If you lie to the compiler,
Email: clive at davros.org     | it will get its revenge.
Web: http://www.davros.org  |   - Henry Spencer
Mobile: +44 7973 377646


More information about the tz mailing list