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

Tom Lane tgl at sss.pgh.pa.us
Sun Nov 6 19:05:55 UTC 2016

Robert Elz <kre at munnari.OZ.AU> writes:
> I had been wondering about the need for nitems_max as a variable though
> and wondered if perhaps

> 	ptrdiff_t	amax = NITEMS_MAX < SIZE_MAX ? NITEMS_MAX : SIZE_MAX;

> might not work just as well, and avoid (at least) the gcc warning
> (though I am yet to actually test this hypothesis).   It will probably
> fall foul of the "constant comparison" warning though.   Ugh!!!

Yeah, I'd been wondering about that too, but it seems unlikely to avoid
warnings.  What about doing the comparison in an #if?

#define AMAX ((ptrdiff_t) NITEMS_MAX)
#define AMAX ((ptrdiff_t) SIZE_MAX)

... then use AMAX in place of the variable ...

			regards, tom lane

More information about the tz mailing list