gmtime change two pointers at the same time

c++, datetime

Solution

From documentation about `gmtime`:

This structure is statically allocated and shared by the functions gmtime and localtime. Each time either one of these functions is called the contents of this structure is overwritten.

Use this code to create a copy:

time_t tt = time(NULL);

tm currentTime = *gmtime(&tt);
tm storedTime = *gmtime(&m_time);

(pointer deference here is equivalent to `memcpy(&currentTime, gmtime(&tt), sizeof(tm))`)

Problem

I have this code: ``` time_t tt = time(NULL); tm* currentTime = gmtime(&tt); tm* storedTime = gmtime(&m_time); ``` Where m_time is a time_t member data set at construction time. When I set storedTime with this data member, current time acquires the same value, as if both tm pointers points to the same variable. Is this the expected behavior? How could I have separated tm structs to compare times? Thanks

Original source