struct timeval 结构体使用浅析
时间结构体struct timeval
的使用
#include <sys/time.h>
该头文件的位置在:/usr/include/x86_64-linux-gnu/sys/time.h
。事实上,该文件只是引入了#include <bits/types/struct_timeval.h>
,并未定义结构体。
(1)struct timeval
结构体定义
/usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h
#include <bits/types.h>/* A time value that is accurate to the nearestmicrosecond but also has a range of years. */
struct timeval
{__time_t tv_sec; /* Seconds. */__suseconds_t tv_usec; /* Microseconds. */
};
(2)__time_t
和__suseconds_t
宏定义
/usr/include/x86_64-linux-gnu/bits/types.h
#define __SLONGWORD_TYPE long int
#define __ULONGWORD_TYPE unsigned long int
/* 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#if __WORDSIZE == 32
# define __SQUAD_TYPE __quad_t
# define __UQUAD_TYPE __u_quad_t
/* We want __extension__ before typedef's that use nonstandard base typessuch as `long long' in C89 mode. */
# define __STD_TYPE __extension__ typedef
#elif __WORDSIZE == 64
# define __SQUAD_TYPE long int
# define __UQUAD_TYPE unsigned long int
/* No need to mark the typedef with __extension__. */
# define __STD_TYPE typedef
#else
# error
#endif
#include <bits/typesizes.h> /* Defines __*_T_TYPE macros. */__STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */
__STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */
gcc
对标准C语言
进行了扩展,但用到这些扩展功能时,编译器会提出警告,使用__extension__
关键字会告诉gcc
不要提出警告。
(3)__TIME_T_TYPE
和__SUSECONDS_T_TYPE
宏定义
/usr/include/x86_64-linux-gnu/bits/typesizes.h
#ifndef _BITS_TYPES_H
# error "Never include <bits/typesizes.h> directly; use <sys/types.h> instead."
#endif/* See <bits/types.h> for the meaning of these macros. This file exists sothat <bits/types.h> need not vary across different GNU platforms. *//* 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
#define __SUSECONDS_T_TYPE __SYSCALL_SLONG_TYPE
#error
命令是C/C++
语言的预处理命令
之一,当预处理器预处理到#error
命令时将停止编译并输出用户自定义的错误消息。
struct timeval 结构体使用浅析相关推荐
- struct timeval结构体
struct timeval结构体在time.h中的定义为: struct timeval { __time_t tv_sec; /* Seconds. */ __suseconds_t ...
- struct timeval结构体 以及 gettimeofday()函数
一.struct timeval结构体 struct timeval结构体在time.h中的定义为: struct timeval { __time_t tv_sec; /* Secon ...
- struct timeval结构体 以及 gettimeofday()函数、struct timespec结构体
struct timeval结构体 struct timeval结构体在time.h中的定义为: struct timeval { __time_t tv_sec; /* Seconds. */ __ ...
- linux系统中struct timeval结构体、struct timezone结构体以及gettimeofday函数
格林尼治时间.协调世界时 间.世界时间.日光节约时间以及时区等介绍: 格林尼治时间(Greenwich Mean Time,GMT)是指位于英国伦敦郊区的皇家格林尼治天文台当地的标准时间,因为本初子午 ...
- timeval结构体的应用
timeval结构体的简单应用 timeval定义 作为计时器 timeval定义 timeval是Linux系统中定义的用于保存时间的结构体,在time.h中的定义为: struct timeval ...
- linux 中 timeval结构体 - Neddy11 - 博客园
linux 中 timeval结构体 - Neddy11 - 博客园 linux 中 timeval结构体 网上很多人写到,timeval结构解释错误 ************************ ...
- struct sk_buff结构体详解
struct sk_buff是linux网络系统中的核心结构体,linux网络中的所有数据包的封装以及解封装都是在这个结构体的基础上进行. 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- linux sock结构体,struct socket结构体详解
在内核中为什么要有struct socket结构体呢? struct socket结构体的作用是什么? 下面这个图,我觉得可以回答以上两个问题. 由这个图可知,内核中的进程可以通过使用struct ...
- C/C++结构体struct 与结构体数组和枚举型enum的结合使用
C/C++结构体struct 与结构体数组和枚举型enum的结合使用 #include "stdafx.h" #include <string> #include &l ...
最新文章
- Nginx学习之负载均衡fair模块
- 05 Linux快速安装 Oracle11g
- python3安装后无法使用退格键的问题
- BTREE与其它索引的优缺点对比
- 激活anaconda的环境出现source: no such file or directory: activate
- vue+element Form键盘回车事件页面刷新解决
- 字符数字转换 atoi 与 strtol
- VB6.0《第二行代码》4-游戏安全,逆向工程-用CE找多级指针HP的基址和偏移量并且用VB超级模块读取
- MySQL安装配置教程(超级详细、保姆级)
- 【NPDP】大师级管理人物盘点:现代管理之父-彼得·德鲁克
- 18-09-20 关于Xlrd和Xlwt的初步学习
- 如何学习单片机?学习单片机的四个步骤
- 理解Linux的平均负载和性能监控
- Flutter 报错:Could not resolve io.flutter:flutter_embedding_debug:1.0.0-ee76268252c22f5c11e82a7b87423c
- 大数据在线分析处理和常用工具
- [《命如草贱》偶感小记]2013-2-17
- 132、网管型和非网管型交换机有什么区别
- 不要仅为85%的用户设计:关注无障碍设计
- 计算机毕业设计Java恩施茶多芬网店系统设计与实现2021(源码+系统+mysql数据库+lW文档)
- 【U8+】UFO报表制作部门资产负债表和部门利润表