Need help with a time() warp

Dave Hammond daveh at marob.masa.com
Fri Oct 6 11:18:55 AEST 1989


System:	386 compatible, SCO Xenix 2.3.1
Compiler:	Microsoft (standard SCO 'cc').

A program I am working on appears to have stepped into a time warp!
Time() is returning values from 2 different clocks -- the current time
and a time which appears off by about 20 years.

The clock appears to flip-flop based upon the return stack depth.
Time() will return valid data in main() and in routines called directly
from main(), but not in routines called from main() subroutines.

I have looked into the obvious things.  The argument passed to time() is
always a valid long integer address {long t, time(); t = time(&t);}.  It
does not matter if the variable declaration is external or auto, nor
whether auto variables are declared on entry to a routine or within a
subsequent block.  In fact, the argument to time() probably does not
enter into the picture, because passing a null argument has the same
effect.

I have noticed a few peculiarities:  BOTH the correct and bogus times
increment normally;  time() always thinks it did the right thing (-1 is
never returned and errno never set);  while the bogus time appears to
represent a future date, ctime() converts it a past date, prior to the
documented zero time (Jan 1. 1970 GMT).

The following edited script traces the situation described above.  MAIN
prefixes lines generated in main(), SUB1 prefixes lines generated in
main() subroutines, and SUB2 prefixes those generated in deeper
subroutines.

Script started [typescript] at Thu Oct  5 15:05:46 1989
$ ./ma tt.m >/dev/null
MAIN:entry:	tim=623617560, errno=0, ctim=Thu Oct  5 15:06:00 1989
SUB2:exe entry:	tim=4294944268, errno=0, ctim=Wed Dec 31 12:36:12 1969
MAIN:init:	tim=623617563, errno=0, ctim=Thu Oct  5 15:06:03 1989
MAIN:source:	tim=623617563, errno=0, ctim=Thu Oct  5 15:06:03 1989
  [top of loop]
SUB1:loop:	tim=623617564, errno=0, ctim=Thu Oct  5 15:06:04 1989
  [the nexet 2 lines are generated by the last statement in the SUB1
  function before calling SUB2 and the first statement in SUB2 after
  variable declarations.]
SUB1:call mr:	tim=623617564, errno=0, ctim=Thu Oct  5 15:06:04 1989
SUB2:mr entry:	tim=4294944284, ctim=Wed Dec 31 12:36:28 1969
SUB2:call mnu:	tim=4294944286, ctim=Wed Dec 31 12:36:30 1969
SUB1:call exe:	tim=623617566, errno=0, ctim=Thu Oct  5 15:06:06 1989
SUB2:exe entry:	tim=4294944286, errno=0, ctim=Wed Dec 31 12:36:30 1969
  [repeat loop]
SUB1:loop:	tim=623617567, errno=0, ctim=Thu Oct  5 15:06:07 1989
SUB1:call mr:	tim=623617567, errno=0, ctim=Thu Oct  5 15:06:07 1989
SUB2:mr entry:	tim=4294944287, ctim=Wed Dec 31 12:36:31 1969
SUB2:call mnu:	tim=4294944288, ctim=Wed Dec 31 12:36:32 1969
SUB1:call exe:	tim=623617568, errno=0, ctim=Thu Oct  5 15:06:08 1989
SUB2:exe entry:	tim=4294944288, errno=0, ctim=Wed Dec 31 12:36:32 1969
  [repeat loop]
SUB1:loop:	tim=623617568, errno=0, ctim=Thu Oct  5 15:06:08 1989
SUB1:call mr:	tim=623617569, errno=0, ctim=Thu Oct  5 15:06:09 1989
SUB2:mr entry:	tim=4294944289, ctim=Wed Dec 31 12:36:33 1969
SUB2:call mnu:	tim=4294944292, ctim=Wed Dec 31 12:36:36 1969
SUB1:call exe:	tim=623617572, errno=0, ctim=Thu Oct  5 15:06:12 1989
SUB2:exe entry:	tim=4294944292, errno=0, ctim=Wed Dec 31 12:36:36 1969
  [end of script]

While I'm sure this is due to some SLB (steenkin' little bug :-), I
can't imagine what would have to be broken to make the program exhibit
this behavior.  It exhibits no other *obvious* bugs or side-effects.
Suggestions as to probable causes, possible solutions or obvious idiocy
would be greatly appreciated.

--
Dave Hammond
daveh at marob.masa.com



More information about the Comp.lang.c mailing list