I’m using ctime function to get a readable representation of time_t variable. ctime is declared as follows:
char *ctime (const time_t *timer);
and you can see that it returns a pointer to the resulting char array without any char pointer passed in arguments. Thus I’m wondering where does ctime allocate char buffer and who will destroy it and isn’t allocating memory inside function (except various malloc‘s, of course) considered to be a mess.
Any suggestions?
From the link you quote:
That array lasts as long as the program does, it must not be freed by anyone.
POSIX 2008 has a
ctime_rfunction that is re-entrant (you pass in your buffer), but it is not standard in C or C++.