time(2 or 3)

guy at sun.UUCP guy at sun.UUCP
Fri Jun 20 04:45:06 AEST 1986


> In article <2021 at umcp-cs.UUCP> chris at maryland.UUCP (Chris Torek) shows
> >>	somevar1 = time(0);
> >
> >       Specifically, time() is a function returning long, taking
> >a _pointer_ to long...;
> >Change to:
> >	...
> >	somevar1 = time((long *) 0);
> 
> Of course Chris is right;  I just ':r some_prog_of_mine' that _worked_(!)...

More precisely, that happened to work on the machine you built it on.  "This
program works" (which almost always means "this program works on some subset
of the machines on which it could conceivably work) is not equivalent to
"this program is correct".  There are *lots* of machines on which "somevar =
time(0);" will *not* work, and such machines have perfectly legal C
implementations.  Those of you on VAXes, Suns, Pyramids, 3Bs, etc. may not
think it matters to write type-correct code, since you can get away with not
doing so; however, you'll regret it the day somebody wants your program
ported to, say, a PC using the large memory model, or a small 68000-based
machine using 16-bit "int"s.

Chris' complaint was perfectly legitimate, as would "lint"s complaint about
the same statement (you *do* run "lint", of course).

> Of course, it helps my case a bit that _my_ manual (albiet an old V7)
> has the following in time(2):  (honest)
> 
> 	long time(0)          <<<< this is what I recommended.

Yes, the V7 manual is old, and you could get away with that sort of thing on
the PDP-11 where V7 was first done.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list