Xref: utzoo comp.unix.sysv386:8273 comp.lang.c:39449 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!haven.umd.edu!decuac!grebyn!ckp From: ckp@grebyn.com (Checkpoint Technologies) Newsgroups: comp.unix.sysv386,comp.lang.c Subject: Re: time(0L) - history of a misconception (was Re: SCO password generator) Message-ID: <1991May22.035411.15379@grebyn.com> Date: 22 May 91 03:54:11 GMT References: <588@sherpa.UUCP> <1141@mwtech.UUCP> <381@tmcsys.UUCP> Organization: Grebyn Timesharing Lines: 57 In article <381@tmcsys.UUCP> lh@aega84.UUCP (L. Hirschbiegel) writes: >In article <1141@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: >>In article <588@sherpa.UUCP> rac@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@grebyn.com (Who needs a fancy .signature?)