libc.so.6 time.c

问题描述

好吧,我放弃了。我一辈子都不会读 C!

  1. 下面time_t的结构是什么?

    /usr/include/bits/types/time_t.h

    #ifndef __time_t_defined
    #define __time_t_defined 1
    
    #include <bits/types.h>
    
    /* Returned by `time'.  */
    typedef __time_t time_t;
    
    #endif
    

此处使用“time_t”:

   /usr/include/bits/types/time_t.h

   /* Return the current time and put it in *TIMER if TIMER is not NULL.  */
   extern time_t time (time_t *__timer) __THROW;

"__THROW" 抛出异常。

  1. 第一个“time_t”是返回值吗?什么是 它的“结构”?难道是神秘的 time_t.h 我 想不通?

  2. 什么是“时间”?这是函数名吗? 是第一个定义结构的“time_t” “时间”的返回值?

  3. 第二个“time_t”是什么?为什么是两个?

  4. 我认为“*___timer”是一个指针,但是指向什么 结构?

  5. tm.h 是否在上述任何地方使用?

     /usr/include/bits/types/struct_tm.h
    
    struct tm
    {
      int tm_sec;        /* Seconds.    [0-60] (1 leap second) */
      int tm_min;        /* Minutes.    [0-59] */
      int tm_hour;        /* Hours.    [0-23] */
      int tm_mday;        /* Day.        [1-31] */
      int tm_mon;        /* Month.    [0-11] */
      int tm_year;        /* Year    - 1900.  */
      int tm_wday;        /* Day of week.    [0-6] */
      int tm_yday;        /* Days in year.[0-365]    */
      int tm_isdst;        /* DST.        [-1/0/1]*/
    
    # ifdef    __USE_MISC
      long int tm_gmtoff;    /* Seconds east of UTC.  */
      const char *tm_zone;    /* Timezone       abbreviation.  */
    # else
      long int __tm_gmtoff;    /* Seconds east of UTC.  */
      const char *__tm_zone;    /* Timezone abbreviation.  */
    # endif
    };
    

    #endif

你的困惑,

解决方法

time_t 是 64 位整数的 long long int。

编辑:回答@lbragile 评论:

当您无法从 .h 标头中找出某些内容时,C 人员给了我一个技巧”

   #include <time.h>

   void func(char*);

   int main(void) {
       time_t x;
       func(x);
   }

然后我尝试像这样使用 gcc 进行编译:

  gcc -c test.c

这会产生以下警告消息:

  C:\c>gcc -c test.c
  test.c: In function 'main':
  test.c:8:10: warning: passing argument 1 of 'func' makes pointer from
   integer without a cast [-Wint-conversion]
     func(x);
          ^
  test.c:3:11: note: expected 'char *' but argument is of type 'time_t'
   {aka 'long long int'}
   void func(char*);
           ^~~~~ 

基本上错误信息会告诉你它是什么。 time_t 是一个 64 位整数:{aka 'long long int'}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...