设为首页 加入收藏

TOP

Linux编程中 #define _XOPEN_SOURCE的作用
2014-11-24 07:46:14 来源: 作者: 【 】 浏览:0
Tags:Linux 编程 #define _XOPEN_SOURCE 作用

[误解]
#define _XOPEN_SOURCE
决不是简单的宏定义
它是使程序符合系统环境的不可缺少的部分


[概念]
Glibc 所实现全部或部分规范下的功能有:
1.ISO C: C语言国际标准.
2.POSIX: 操作系统的 ISO/IEC 9945 (aka IEEE 1003) 标准.
3.Berkeley Unix: BSD 和 SunOS.
4.SVID: V 系统接口描述.
5.XPG: The X/Open Portability Guide.


程序中,为了实现上述功能需要定义对应的宏。如第二个功能POSIX,应定义 _POSIX_SOURCE。类似的有 _BSD_SOURCE、_SVID_SOURCE、_XOPEN_SOURCE。
也就是说:
#define _XOPEN_SOURCE
是为了可以使用 5. The X/Open Portability Guide 的功能。


[实用方法]
使用上述五种功能的方法有两种:
1)在cc命令中指定,如:cc -D _POSIX_SOURCE file.c
2)将源程序的第一行设置为:#define _POSIX_SOURCE 1


[_XOPEN_SOURCE是什么?]
翻译成汉语表达很蹩脚,英文原版解释如下:
Macro: _XOPEN_SOURCE
If you define this macro, functionality described in the X/Open Portability Guide is included. This is a superset of the POSIX.1 and POSIX.2 functionality and in fact _POSIX_SOURCE and _POSIX_C_SOURCE are automatically defined.
As the unification of all Unices, functionality only available in BSD and SVID is also included.
If the macro _XOPEN_SOURCE_EXTENDED is also defined, even more functionality is available. The exa functions will make


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇嵌入式Linux即时通讯的实现 下一篇编写Linux Shell程序

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)