The UNIX time(2) system call, time_t time(time_t *t);
, returns the current time in two ways: return value and return-by-reference. What's the rational for this redundancy? Why not just define it time_t time(void);
?

- 1,707
- 17
- 23
-
1possible duplicate of [Why does time(time\_t \*) function both return and set the by-ref?](http://stackoverflow.com/questions/9944771/why-does-timetime-t-function-both-return-and-set-the-by-ref) – Alok Singhal Mar 12 '13 at 03:37
-
My bad. Didn't find it. – Wu Yongzheng Mar 12 '13 at 06:41
1 Answers
Ancient history, but it is probably related to the time when a long was simulated by two 16-bit int
values in tandem. Otherwise, there's no real obvious reason. Interestingly, the UNIX™ 7th Edition Manual documents time
as obsolete:
NAME
time, ftime – get date and time
SYNOPSIS
long time(0)
long time(tloc)
long *tloc;
#include <sys/types.h>
#include <sys/timeb.h>
ftime(tp)
struct timeb *tp;
DESCRIPTION
Time returns the time since 00:00:00 GMT, Jan. 1, 1970, measured in seconds. If tloc is nonnull, the return value is also stored in the place to which tloc points. The ftime entry fills in a structure pointed to by its argument, as defined by
<sys/timeb.h>
:/* * Structure returned by ftime system call */ struct timeb { time_t time; unsigned short millitm; short timezone; short dstflag; };
The structure contains the time since the epoch in seconds, up to 1000 milliseconds of more-precise interval, the local timezone (measured in minutes of time westward from Greenwich), and a flag that, if nonzero, indicates that Daylight Saving time applies locally during the appropriate part of the year.
SEE ALSO
date(1), stime(2), ctime(3)
ASSEMBLER
(ftime = 35.) sys ftime; bufptr (time = 13.; obsolete call) sys time (time since 1970 in r0-r1)
Note the designation 'obsolete call', and note that the return value was in two (16-bit) registers, r0 and r1.

- 730,956
- 141
- 904
- 1,278