c++ - 使用 Visual C++ 2008 时如何解决未处理的异常错误?

标签 c++ c visual-studio-2008 visual-c++ exception

有人可以帮我解决使用 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/

相关文章:

c++ - 没有运算符 "<"匹配这些操作数操作数类型是 : double < my_class

php - 为什么 PHP 浮点除法和 POW 会给出错误的结果和意想不到的结果?

c++ - 错误 C2011 : 'MSXML2::IXMLDOMImplementation' : 'struct' type redefinition

asp.net - 将 ContentPlaceHolder 放在 &lt;script&gt; 标记中时出现问题

c# - 从引用中删除版本号(避免 "Could not load file or assembly..."错误)?

c++ - 您如何使用运算符 | 创建与现有 View 交互的自己的 View ?

c++11 使用 std::swap 与 operator=(T&&) 清除容器

c++ - linux中的内存分配是非阻塞的吗?

c - 初始化 - C 中的多维数组

C - 为什么在进行指针运算时转换为 uintptr_t 与 char*