ANSI 'C'.
Henry Spencer
henry at utzoo.UUCP
Sat Nov 23 11:09:41 AEST 1985
> And then they define a function gmtime(const time_t *timer) that takes
> a pointer to the arithmetic value, which it is not going to change anyway.
> Why not just take the value itself instead of the pointer?
*That* one, at least, is easy to explain: because that is the way the
Unix function does it, for historical reasons, and nobody wants to break
all that working code.
As for why the Unix function does it that way... gmtime() predates the
arrival of "long" in C. Back In The Bad Old Days, with no type "long",
32-bit values had to be manipulated as small arrays of int. There were
functions to add them, etc. Note that one can pass the address of an
array but not the array itself. And that's why virtually all Unix library
functions that deal with time take pointers to time_t rather than just
time_t. (If you want a really odd example, look at the time(2) manual
page -- it has two different ways to return its value!)
Oh yes, a word to the careless (and to Laura for her book): one should
not assume that time_t and long are the same type. Sometimes they're not,
old (e.g. V7) or broken (e.g. 4.2BSD) manuals notwithstanding.
--
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,linus,decvax}!utzoo!henry
More information about the Comp.lang.c
mailing list