[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: time returns -1




On Thu, 9 Nov 1995, Dale Scheetz wrote:

> 
> On Thu, 9 Nov 1995, Richard Kettlewell wrote:
> 
  ( Richard's example)
> > 
> Well, Richard, my code looks a little different, but I think the net 
> result is the same:
> 
> function()
> 	{
> 	time_t *jt;
> 	time_t jtime;
> 	
> 
> 	jtime = time(jt);

Here you're passing an uninitialized pointer to time(). Seems
like a bad idea! You're relying on the compiler to make sure
your local vars are initialized to nulls, which may not be the
case (I've not tried it with Debian compilers, but it coredumps
on an AIX box).

> 	printf("jtime = %i", (int)jtime);
> 	}
> 
> This code prints out:
> 
> jtime = -1
> 
> if I put the line:
> 
> jt = malloc(sizeof(time_t));
> 
> just before the call to time I get:
> 
> jtime = 854563279

My AIX box says 
  jtime = 815926677  
Your system clock must be running a bit fast ;)

> 
> Memory says that my first code worked fine in R5 also. Can someone check 

You may have just been lucky with initializations then.

> this out on an R6 machine? If this is a bug, how do I report it?
> 
> Thanks,
> 
> Dale
> 
> 




Reply to: