【问题标题】:Porting time APIs from Linux to Visual Studio 2008将时间 API 从 Linux 移植到 Visual Studio 2008
【发布时间】:2012-01-08 05:43:15
【问题描述】:

我有一个应用程序要移植到 Microsoft Visual Studio 2008,它可以在 Linux 上构建和运行良好。

我的时间程序有问题,我的 Linux 代码如下所示:

#include <sys/types.h>
#include <sys/time.h>

typedef long long Usec;

inline Usec timevalToUsec(const timeval &tv)
{
  return (((Usec) tv.tv_sec) * 1000000) + ((Usec) tv.tv_usec);
}

但编译器在sys/time.h 头文件上失败:

fatal error C1083: Cannot open include file:
      'sys/time.h': No such file or directory

如果我将包含更改为 time.h,我会得到一个不同的错误,即 timeval 未定义:

error C4430: missing type specifier - int assumed.
      Note: C++ does not support default-int

这是因为 timeval 没有被定义。

包含time.h 而不是sys/time.h 是否正确,如果是,我在哪里可以得到Microsoft Visual Studio 2008 中struct timeval 的定义?

【问题讨论】:

    标签: c++ visual-studio-2008 time porting timeval


    【解决方案1】:

    winsock2.h 标头填充将引入 struct timeval,因为它用于像 select 这样的调用。

    【讨论】:

      【解决方案2】:

      它存在,只是不在“sys/time.h”中。有趣的是,Timeval 在 Winsock2.h 中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多