On Fri, Jun 07, 2013 at 09:37:45PM +0000, Thorsten Glaser wrote: > Kurt Roeckx dixit: > > >tm_year should be an int, not a time_t or long. Note that it > > POSIX says it "must" be a long...
It doesn't say so here. It has it as an int. Also note that time_t didn't have a requirement to be an integer type, but as far as I know it does now. And you really want an integer type for the values in struct tm. > >counts in years, and so even a 16 bit int isn't going to cause > >much problems for tm_year. > > ... but I disagree. All time_t seconds-since-the-epoch values > need (in practice) to round-trip through "struct tm", which > requires tm_year to be of a type of the magnitude time_t has: If you add that requirement, it can be upto 24 bit smaller than time_t. But as far as I know, there is no such requirement. In fact POSIX defines an error code for that case. > tg@blau:~ $ cat x.c > #include <limits.h> > #include <stdio.h> > #include <time.h> > int main(void) { struct tm *tm; time_t tmax = LLONG_MAX; tm = gmtime(&tmax); > printf("%lld\n", (long long)tm->tm_year); return (0); } > tg@blau:~ $ ./a.out > 292277024696 tm should be NULL in this case, an errno EOVERFLOW. If that's not the case I suggest you file a bug against libc. It's at least what I get here. Kurt -- To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20130607220656.ga12...@roeckx.be