有人可以帮我解决使用 Visual C++ 2008 时未处理的异常错误吗?错误显示如下:Time.exe 中 0x00411690 处未处理的异常:0xC0000005:访问冲突读取位置 0x00000008
一些细节:
-tm 0x00000000 {tm_sec=??? tm_分钟=??? tm_小时=??? ...}tm *
tm_sec CXX0030:错误:无法计算表达式
...
其实我以前用Visual C++ 6的时候,没有任何错误,程序运行得很好。但现在当我使用 Visual 2008 时,我收到此未处理的异常错误。
这是程序:
...
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; /*convert into microseconds*/
/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
uint32_t stampstart()
{
struct timeval tv;
struct timezone tz;
struct tm *tm;
uint32_t start;
gettimeofday(&tv, &tz);
tm = localtime(&tv.tv_sec);
printf("TIMESTAMP-START\t %d:%02d:%02d:%d (~%d ms)\n", tm->tm_hour,
tm->tm_min, tm->tm_sec, tv.tv_usec,
tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000); /////---debugger stops here---
start = tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000;
return (start);
}
感谢您的回复:
最佳答案
尝试类似...
tm = localtime(&tv.tv_sec);
if(tm)
{
printf("TIMESTAMP-START\t %d:%02d:%02d:%d (~%d ms)\n", tm->tm_hour,
tm->tm_min, tm->tm_sec, tv.tv_usec,
tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000);
start = tm->tm_hour * 3600 * 1000 + tm->tm_min * 60 * 1000 +
tm->tm_sec * 1000 + tv.tv_usec / 1000;
}
else
{
// failed to retrive local time
}
关于c++ - 使用 Visual C++ 2008 时如何解决未处理的异常错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2490449/