This rises an interesting question:
Why does the C library functions always access time_t values by constant pointers and not by simply copying the value???
I never understood this part of the C lib API. How is portability increased by not using a call-by-value here?
Okay, all who remember the "portable C compliler" under v6 Unix raise your hand... Hmm, not too many hands up. The "long" datatype was not one that could be passed as a function parameter, nor returned as a function value, back in days of yore. But a (16 bit) int time() value wasn't big enough to hold any reasonable time inteval. So the time() function was passed a pointer to a long to fill, and the localtime(), gmtime() functions were passed pointers to longs (not time_t back in those days, just long ints) to make use of. The language evolved to permit longs, and later even structs, to be passed to and returned from functions, but the API of the time functions lives on.
If there is any good reason that this has been done in libc, then I'd of course also add it to my code. I already did it for consistency with the existing library functions, but I'd like to know why this is supposed to be the right thing to do.
The only reason is "historical practice". I feel that the existing C API is suboptimal in the design of its time functions, but I recognize that the weight of remaining compatible with what was then the only "existing practice" was too great for the ANSI C8x committee to change these APIs.
� Comparing t with 0 doesn't take any sense (I know one system where � (time_t)0 is J2000,0, so negative t are allowed before 2000-01-01 12:00:00Z
Ok, you are right. I just hope that the system you know does not encode
2000-01-01 11:59:59Z = (time_t) -1
as this value is reserved by the standard for error conditions.
A problematical situation on any implementation is distinguishing between an error return from mktime() and mktime() returning a legitimate -1 value. Another unpleasantness of the API. But this is the only place besides time() where the C standard has a function returning a time_t, and time() is not defined to have an error return. --Ken Pizzini