Operating System - HP-UX
1752670 Members
5822 Online
108788 Solutions
New Discussion

Re: Problem with "time" in C programming

 
SOLVED
Go to solution
A. Clay Stephenson
Acclaimed Contributor

Re: Problem with "time" in C programming

localtime() would never free the data structure. If localtime() is supplied a NULL pointer then it returns the address of a static variable that is reused upon each invocation of the function. In that case, it is imperitive to copy the values to other variable before calling localtime again. If a non-NULL pointer is supplied then localtime stores the value there and it is the responsibility of the calling program to then free any dynamically allowcated memory.
If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: Problem with "time" in C programming

>if you send in a non-null pointer to time()

 

You shouldn't do this because it causes the kernel to sweat.  Just use the return result.

 

>If localtime() is supplied a NULL pointer

 

localtime(3) would probably abort on a NULL.  Are you thinking of localtime_r?

 

>If a non-NULL pointer is supplied then localtime(3)

 

The input parm is of time_t*.