Question: localtime()
-
I am trying to compile a project written in Visual C++ 6 in Visual Studio 2005. And I have an error, saying error C2664: 'localtime' : cannot convert parameter 1 from 'long *' to 'const time_t *' Below is the snippet of the file long totalSeconds = (long)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds);//Convert to local tim Anybody can help me? Yonggoo
-
I am trying to compile a project written in Visual C++ 6 in Visual Studio 2005. And I have an error, saying error C2664: 'localtime' : cannot convert parameter 1 from 'long *' to 'const time_t *' Below is the snippet of the file long totalSeconds = (long)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds);//Convert to local tim Anybody can help me? Yonggoo
Short answer: The prototype for localtime is: struct tm *localtime(const time_t *timer); You are passing a long* not a time_t*. Longer answer: time_t is a long in 32-bit OS's but a __int64 in 64-bit OS's. As time_t has been a long for a long time (no pun intended) many developers found it more convenient to just use a long. In VS2005 time_t is a __int64 unless _USE_32BIT_TIME_T is defined. So, in reality you are passing a long* to a function expecting a __int64*. Just use time_t, there is a reason it is defined as a distinct type. e.g. time_t totalSeconds = (time_t)(dSeconds +.5); struct tm *myTime = localtime(&totalSeconds); ...cmk Save the whales - collect the whole set