time(0L) - history of a misconception (was Re: SCO password generator)
Tim Wright
tim at dell.co.uk
Wed May 22 18:55:29 AEST 1991
In <381 at tmcsys.UUCP> lothar at tmcsys.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
>>
>You're a cousin of "lint", aren't you :-) ?
>>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.
>If you still don't understand: I'll help you!
>For this little test program:
Yes but it's a pointer i.e. they are talking about a non-zero or non-null
pointer. If the compiler allows prototypes, it can cast a 0 correctly.
Without prototypes it cannot.
>main()
>{
>time(0L);
>time((long *)0);
>}
>the assembler output from my C compiler is:
...
irrelevant :-)
>>Repeat after me: POINTER to long.
>Repeat after me: IT DOESN'T MATTER :-)
*WRONG* *WRONG* *WRONG*. Just because it doesn't happen to matter on
*YOUR* machine with *YOUR* C compiler does not mean it does not matter.
On a non-ansi compliant compiler on a '286 system it is possible to
choose a memory model where sizeof(long) != sizeof(long *).
In this case the code generated will be somewhat different :-)
Tim
--
Tim Wright, Dell Computer Corp., Bracknell | Domain: tim at dell.co.uk
Berkshire, UK, RG12 1RW. Tel: +44-344-860456 | Uucp: ...!ukc!delluk!tim
Smoke me a Kipper, I'll be back for breakfast - Red Dwarf
More information about the Comp.unix.sysv386
mailing list