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

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -