4.2BSD ctime() arguments
ado at elsie.UUCP
ado at elsie.UUCP
Tue Apr 17 02:15:07 AEST 1984
Henry Spencer notes:
. . .The argument to gmtime() should be of type "time_t",
and ***ONLY*** time_t. Just exactly what kind of int time_t is, is
something that is machine-dependent and system-dependent; you are not
supposed to imbed such assumptions into your programs!
The manual page is a bit out of date. The lint library is correct.
The include file is machine-dependent and 4.2BSD-dependent. . .it
*should* have been "typedef long time_t"! It makes no actual difference
on the VAX, but it makes the portability situation a lot clearer.
There are a *LOT* of Unix machines where time_t is not int. . .
The "ctime" manual page on our 4.1 system has "7th Edition" in the
lower-left-hand corner. I suspect that on "7th Edition" systems the way to call
"ctime" is STILL with a "long *". I don't know if the "sys/types.h" file in
which "time_t" is "typedef"d is even present on "7th edition" systems.
Is there anyone out there who does?
(And what's the situation on System V with respect to the "ctime" argument?)
On our 4.1 system, the lint library (or the "ctime" source code, take your
pick) is wrong. The lint library claims that "ctime" takes a "time_t *" as
its argument, where "time_t" has been "typedef"d to be an "int".
But "ctime.c" reads (in part):
char *
ctime(t)
long *t;
{ . . .
which says that "ctime" takes a "long *" as its argument.
Maybe this discrepancy has been fixed in 4.2bsd.
Then again, maybe it has been replaced with a new discrepancy.
Can anyone running 4.2 shed light on this?
The bottom lines: to keep "lint" happy and ensure portability, I'd do this:
#ifdef vax
#include <sys/types.h>
time_t timearg;
#else
long timearg;
#endif
--
UNIX is an AT&T (or Bell Labs, or AT&T Bell Labs) trademark.
(Can some AT&T mouthpiece post the preferred form for this note?)
VAX is a Digital Equipment Corporation trademark.
TIME is a Time/Life, Incorporated trademark.
--
UUCP: decvax!harpo!seismo!rlgvax!cvl!elsie!ado
DDD: (301) 496-5688
More information about the Comp.unix.wizards
mailing list