time(0L) - history of a misconception

Brian Matthews 6sigma2 at polari.UUCP
Fri May 24 02:28:19 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
|Ever tried to RTFM for yourself? 
|
|	  NAME
|	       time - get time
|	       If tloc is non-zero, the	return value is	also stored in the
|                   ^^^^^^^^^^^
|	       location	to which tloc points.

You'll get yourself in trouble by taking parts of TFM out of context.
The part you left out reads something like:

	long time ((long *) 0)
	long time (tloc)
	long *tloc;

Tloc still has to be of the correct type, whether zero or non-zero.  This
can happen by having a prototype in scope or with an appropriate cast.

|If you still don't understand: I'll help you! 
|For this little test program:
|[program calling time with (incorrect) 0L and (correct) (long *)0]

This just proves that on your particular OS at some particular release
level and version with some particular version of gcc, it happens to
work.  In general, portable code must assume time(0L) won't work.

|Repeat after me: IT DOESN'T MATTER :-)

Please remind me never to use any code you've written.  It will
undoubtedly fail in many strange and mysterious (to you at least) ways.



More information about the Comp.unix.sysv386 mailing list