【问题标题】:What is the structure of libc.so.6 time.clibc.so.6 time.c的结构是什么
【发布时间】:2020-12-25 15:00:52
【问题描述】:

好吧,我放弃了。我一辈子都看不懂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 和 __time_t 是不同的标识符。你提到tm.h,然后引用了一个完全不同的头文件。
  • 嗨@Florian,typedef __time_t time_t; 表示time_t 属于__time_t 类型。我直接引用/usr/include/bits/types/time_t.h。你的不一样吗?

标签: libc time.h


【解决方案1】:

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'}

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
  • @lbragile,是的。问题是“下面 time_t 的结构是什么?”。答案是它是一个 {aka 'long long int'} 或 long、long 整数、64 位整数或 int64。它完美地回答了我的问题。去stackoverflow.com/questions/65421378/…看看我的使用情况@
猜你喜欢
  • 2011-09-23
  • 2012-11-27
  • 2019-08-10
  • 1970-01-01
  • 1970-01-01
  • 2014-05-22
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
相关资源
最近更新 更多