time(0L)

Walter Bright bright at nazgul.UUCP
Sat May 25 06:12:44 AEST 1991


In article <4138 at uc.msc.umn.edu> jeff at uf.UUCP (Jeff Turner) writes:
/Perhaps you are confusing time(0) with time(0L).  Calling time(0) on a 16-bit
/machine (e.g. PCs not running 386 UNIX) will push only a 16 bit value onto the
/stack instead of the 32 bit address that time() is expecting (and is going to
/use).  Since half of the 32-bit address will have a random (and probably
/non-zero) value, time() will use it as an address to store the current time
/into, and bash your memory or cause range-error core-dump.

Actually, in all the 16 bit compilers I'm currently familiar with,
time() is prototyped such that the argument is correctly cast, and the
problem doesn't arise. For instance, time(long *) being the prototype,
time(0) becomes time((long*)0) which will always work correctly.

The time you unavoidably get into trouble is if it is a varargs function
like printf().



More information about the Comp.lang.c mailing list