time_t的类型

在毕设中用到了time_t的类型,但是发现在types.h里面没有找到它的具体定义,只知道是8个字节长度,于是
写了下面这段测试代码:

#include <stdio.h>
#include <time.h>
#include <sys/types.h>
int main(int argc,char *argv[])
{
    u_int64_t s1=(1<<31);
    int64_t s2=(1<<31);
    time_t  s3=(1<<31);
    printf("sizeof(s1)=%ld,s1>0? %s\n",sizeof(s1),s1>0?"true":"false");
    printf("sizeof(s2)=%ld,s2>0? %s\n",sizeof(s2),s2>0?"true":"false");
    printf("sizeof(s3)=%ld,s3>0? %s\n",sizeof(s3),s3>0?"true":"false");
    return 0;
}

输出如下:

sizeof(s1)=8,s1>0? true
sizeof(s2)=8,s2>0? false
sizeof(s3)=8,s3>0? false

所以可以知道time_t的类型是8字节的有符号整数。



time.h中,time_t是这样定义的:

// 在cdefs.h
//# define __USING_NAMESPACE_STD(name) using std::name;

__BEGIN_NAMESPACE_STD
/* Returned by `time'.  */
typedef __time_t time_t;
__END_NAMESPACE_STD
#ifdef __USE_POSIX
__USING_NAMESPACE_STD(time_t)
#endif

/usr/include/x86_64-linux-gnu/bits/types.h中:

# define __STD_TYPE		typedef
__STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch.  */

/usr/include/x86_64-linux-gnu/bits/typesizes.h中:

/* X32 kernel interface is 64-bit.  */
#if defined __x86_64__ && defined __ILP32__
# define __SYSCALL_SLONG_TYPE	__SQUAD_TYPE
# define __SYSCALL_ULONG_TYPE	__UQUAD_TYPE
#else
# define __SYSCALL_SLONG_TYPE	__SLONGWORD_TYPE
# define __SYSCALL_ULONG_TYPE	__ULONGWORD_TYPE
#endif
#define __TIME_T_TYPE		__SYSCALL_SLONG_TYPE

/usr/include/x86_64-linux-gnu/bits/types.h

/* quad_t is also 64 bits.  */
#if __WORDSIZE == 64
typedef long int __quad_t;
typedef unsigned long int __u_quad_t;
#else
__extension__ typedef long long int __quad_t;
__extension__ typedef unsigned long long int __u_quad_t;
#endif
#define __SLONGWORD_TYPE	long int
#if __WORDSIZE == 32
# define __SQUAD_TYPE		__quad_t
#elif __WORDSIZE == 64
# define __SQUAD_TYPE		long int
#else
# error
#endif

/usr/include/x86_64-linux-gnu/bits/wordsize.h中:

#if defined __x86_64__ && !defined __ILP32__
# define __WORDSIZE	64
#else
# define __WORDSIZE	32
#endif

/usr/include/x86_64-linux-gnu/sys/cdefs.h中:

/* It is possible to compile containing GCC extensions even if GCC is
   run in pedantic mode if the uses are carefully marked using the
   `__extension__' keyword.  But this is not generally available before
   version 2.8.  */
#if !__GNUC_PREREQ (2,8)
# define __extension__		/* Ignore */
#endif

/usr/include/features.h中:

/* Convenience macros to test the versions of glibc and gcc.
   Use them like this:
   #if __GNUC_PREREQ (2,8)
   ... code requiring gcc 2.8 or later ...
   #endif
   Note - they won't work for gcc1 or glibc1, since the _MINOR macros
   were not defined then.  */
#if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define __GNUC_PREREQ(maj, min) 0
#endif
  • 13
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值