Linux ---#include <time.h>和 #include <sys/time.h>的区别
2015-03-14 12:08
423 查看
搜索了好几个,都是这么说的,有点看不明白。分析一下:
相同点: 二者都是与 日期时间相关的 头文件。
不同点:
time.h 是c99的,也就是c的库函数。
sys/time.h是linux系统的。
time.h既然是c库函数,那么在具体的平台上,就就可以依靠平台而实现,所以看上去是与平台无关的,谁都可以调用.
而 sys/time.h 只是在linux系统上可以调用。
按照下文的意思:
time_t 这样的结构,是linux的,所以,如果只是调用time.h,那么,就没有了time_t这样的结构,
所以在仅仅使用 c的time.h的时候,需要自己实现定义time_t结构:
下面好像不是定义time_t,而是 判断是否需要time_t 这个结构的宏定义。
#define __need_time_t
#define __need_timespec
===============================
交叉编译情况下,两个文件的地址
/opt/gcc-4.1.2-glibc-2.4/arm-xscale-linux-gnu/arm-xscale-linux-gnu/include/time.h
/opt/gcc-4.1.2-glibc-2.4/arm-xscale-linux-gnu/arm-xscale-linux-gnu/include/sys/time.h
time.h 是ISO C99 标准日期时间头文件。
sys/time.h 是Linux 系统的日期时间头文件。
sys/time.h 通常会包含include time.h
编写的代码如果是平台无关的,则需要在代码里include time.h.
但这样的话,使用time_t等数据结构的话可能需要手动
#define __need_time_t
#define __need_timespec
通常如果代码可以是平台相关的,则只需要include sys/time.h
相同点: 二者都是与 日期时间相关的 头文件。
不同点:
time.h 是c99的,也就是c的库函数。
sys/time.h是linux系统的。
time.h既然是c库函数,那么在具体的平台上,就就可以依靠平台而实现,所以看上去是与平台无关的,谁都可以调用.
而 sys/time.h 只是在linux系统上可以调用。
按照下文的意思:
time_t 这样的结构,是linux的,所以,如果只是调用time.h,那么,就没有了time_t这样的结构,
所以在仅仅使用 c的time.h的时候,需要自己实现定义time_t结构:
下面好像不是定义time_t,而是 判断是否需要time_t 这个结构的宏定义。
#define __need_time_t
#define __need_timespec
===============================
#include time.h和 #include sys/time.h的区别
交叉编译情况下,两个文件的地址/opt/gcc-4.1.2-glibc-2.4/arm-xscale-linux-gnu/arm-xscale-linux-gnu/include/time.h
/opt/gcc-4.1.2-glibc-2.4/arm-xscale-linux-gnu/arm-xscale-linux-gnu/include/sys/time.h
time.h 是ISO C99 标准日期时间头文件。
sys/time.h 是Linux 系统的日期时间头文件。
sys/time.h 通常会包含include time.h
编写的代码如果是平台无关的,则需要在代码里include time.h.
但这样的话,使用time_t等数据结构的话可能需要手动
#define __need_time_t
#define __need_timespec
通常如果代码可以是平台相关的,则只需要include sys/time.h
相关文章推荐
- 解决VC6 --> VC2005 --> VC2008 中没有<sys/time.h> 问题
- include <cstring>,include <string> include <string.h>的区别
- <%@ include file=""%>与<jsp:include page=""/>区别
- <%@include%> 和 jsp:include 区别
- c++中#include<iostream>、<iostream.h>区别
- #include命令, #include <>与#include ””的区别
- #include<iostream>与#include<iostream.h>以及#inclue<string> 和 #include<string.h>的区别
- <%@ include file=”relativeURI”%>与<jsp:include page=””>的区别
- #include <sys/types.h>的作用
- <%@ include file=""%>与<jsp:include page=""/>区别
- #include   <> 和#include   " "的区别
- char* 赋值时单引号和双引号的区别?include”“和include<>的区别
- #include " "与#include <> 的区别
- #include<iostream>与#include<iostream.h>的区别
- #include <filename.h> 和 #include “filename.h”有什么 区别
- <jsp:include>与include指令的区别
- #include<iostream>与#include<iostream.h>及#inclue <string> 和 #include <string.h>的区别
- C++中include <iostream>和include <iostream.h>的区别
- <%@ include file=""%>与<jsp:include page=""/>区别
- #include <iostream>与#include <iostream.h>的区别