On Oct 26, 2:33 am, bill <bill21...@zippycode.netwrote:
It appears that the only parameter that can be passed to
time() is 0.
Nonsense. You can pass any legal address of a time_t to it.
No other number works (because converting from int to
time_t*).
No number works, because the parameter doesn't have a numeric
type, but a pointer type. You can only pass it a pointer.
If that's true, why does it even accept a parameter?
Because that's where it puts the results.
Historically, I think that time() was defined before you could
return a long. (The very earliest C only allowed returning int,
double and pointers.) And time_t was a typedef for a long.
(The machine was a 16 bit PDP-11. And 16 bits is a bit limited
for the time in seconds, regardless of the epoch you choose.)
So the logical signature was "void time_t( long* )". (Of
course, there were no signatures at the time. And there was no
void, either; the compiler considered it to be a function
returning int, but the int value was indeterminate.)
Once you could return long, the function was modified to return
the results. But to avoid breaking existing code, it continued
to take a pointer to the results; if the pointer is not null, it
will store the results there as well.
Note that this historical reason also explains why functions
taking a time_t also have a time_t const* parameter, rather than
just a time_t. I don't think you could pass a long as an
argument either.
(I know you couldn't pass or return struct's until much later.
And on a 16 bit machine, a long is really implemented as a
struct.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34