time(0L) - history of a misconception (was Re: SCO password generator)

Checkpoint Technologies ckp at grebyn.com
Wed May 22 13:54:11 AEST 1991


In article <381 at tmcsys.UUCP> lh at aega84.UUCP (L. Hirschbiegel) writes:
>In article <1141 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
>>In article <588 at sherpa.UUCP> rac at sherpa.UUCP (Roger Cornelius) writes:
>>[...]
>>>	long seed = time(0L);
>>	                 ^^--------- wrong
>>	           time((long *)0);
>>	                ^^^^^^^^^--- right
>>
>>Note that the argument to the time system call is a `long *', aka
>>pointer to long. 
>
>Ever tried to RTFM for yourself? 
>
>	  NAME
>	       time - get time
>
>	  DESCRIPTION
>	       The time	system call returns the	value of time in seconds
>	       since 00:00:00 Greenwich	Mean Time (GMT), January 1, 1970.
>
>	       If tloc is non-zero, the	return value is	also stored in the
>                   ^^^^^^^^^^^
>	       location	to which tloc points.

You omitted the SYNOPSIS for time: "time_t time(tloc) time_t *tloc;",
which clearly shows that the argument to time() is a pointer to a
time_t (which BTW is the *real* correct answer).  This man page uses an
archaic style when using the term "non-zero".  Read the FAQ for the whole
poop on NULL and 0; there is a place in C where 0 is treated as
NULL, but arguments to functions sans prototype isn't one of them.

>For this little test program:
>
>main()
>{
>time(0L);
>time((long *)0);
>}
>
>the assembler output from my C compiler is:
> [ omitted; irrelevant ]

BIG mistake.  The assembly language output from the C compiler shows all
the implementation details, including the ones which are not guanteed to
be portable.  You will not learn portable C programming this way, quite
the opposite.  There's no favor from anyone in comp.lang.c for
arguing how widely applicable implementation details are; all the
world's NOT a VAX or i386...

>>Repeat after me: POINTER to long.
>Repeat after me: IT DOESN'T MATTER :-)

Too many programmers repeat after you as it is.  It does matter.
-- 
Richard Krehbiel, private citizen      ckp at grebyn.com
(Who needs a fancy .signature?)



More information about the Comp.unix.sysv386 mailing list