【问题标题】:error in compiling c program in ubuntu "storage size of time_struct isn't know"在 ubuntu 中编译 c 程序时出错“不知道 time_struct 的存储大小”
【发布时间】:2013-01-21 11:54:18
【问题描述】:

您好,我尝试使用 gcc 编译 C 程序,但出现此错误:

timerc.c:在函数“timer_”中: timerc.c:32:16:错误:“Time_Struct”的存储大小未知

这是程序:

#include <sys/types.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
void timer_(long *UnixSysTime)
{
  int dummy;
  struct timeb Time_Struct;
  dummy=ftime(&Time_Struct);
  *UnixSysTime=Time_Struct.time;
}

【问题讨论】:

  • man ftimeSYNOPSIS: #include &lt;sys/timeb.h&gt;。另外,CONFORMING TO: ... This function is obsolete. Don't use it.
  • @melpomene 手册页ftw :)

标签: c ubuntu compiler-errors


【解决方案1】:

添加

#include <sys/timeb.h>

在其他包含行之后。

那么编译器会知道他的存储大小

【讨论】:

    【解决方案2】:

    当你声明结构变量时:

      struct timeb Time_Struct;
    

    编译器不知道它的定义。因此,它无法为其分配内存。 包含定义此结构的头文件。

    【讨论】:

      【解决方案3】:

      在我的系统ubunt 12.04 LTS中,位置是/usr/include/x86_64-linux-gnu/sys目录。

      对于 32 位机器,它的位置是 /usr/include/i386-linux-gnu/sys。

      查看 timeb.h 文件以获取有关 struct timeb 等的更多详细信息

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-19
        • 1970-01-01
        • 2018-03-05
        • 2019-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多