c++ - Why doesn't need to malloc struct tm pointer before call localtime() function? -


my code is

#include <iostream> #include <ctime>  using namespace std;  void main() {     time_t nowtime;     struct tm *nowstruct;      time(&nowtime);      nowstruct = localtime(&nowtime);     cout << nowstruct->tm_hour << ":" << nowstruct->tm_min << endl; } 

i suspect address of memory used store struct tm.

localtime uses internal, global buffer (or perhaps thread-local), address returns. practice of keeping global state around similar how strtok , rand work. note makes function inherently non-rentrant, , perhaps thread-unsafe.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -