char* asctime (const struct tm * timeptr);
char* ctime (const time_t * timer);
I found that many functions inside of time.h
return pointers to static variables, which could be altered by any subsequent call to those functions. That means I have to copy the data I just got as a result and it's an extra operation I have to execute and that makes those functions thread-unsafe.
Why was it implemented that way? Wouldn't these signatures be better?
void asctime (char * out, const struct tm * timeptr);
void ctime (char * out, const time_t * timer);
We always have to take decisions during development. I'm just asking why they chose to return a static pointer instead of taking an "out variable" as a parameter.
By the way (this is another question), why don't they allocate their result on the heap? Is it to allow the use of anything instead of malloc or just for efficiency?