诡异的_GNU_SOURCE宏
来源:互联网 发布:bad sql grammar 编辑:程序博客网 时间:2024/05/19 11:19
好久没更新博客了,突然来一篇,这...难道是干货?......在看正文之前请允许我先说几句话,。好了看下面的内容:
诡异代码之test.c:
#include <aio.h>
int main()
{
struct aioinit aa;
aa.aio_threads = 10;
return 0;
}
使用glibc的aio需要在链接时,用-lrt:
gcc -o test test.c -lrt
test.c:4: error: storage size of ‘aa’ isn’t known
Why ???
代码修改一下:
#define _GNU_SOURCE
#include <aio.h>
int main()
{
struct aioinit aa;
aa.aio_threads = 10;
return 0;
}
就OK了。Why?
Defining _GNU_SOURCE
has nothing to do with license and everything to do with writing (non-)portable code. If you define _GNU_SOURCE
, you will get:
access to lots of nonstandard GNU/Linux extension functions
access to traditional functions which were omitted from the POSIX standard (often for good reason, such as being replaced with better alternatives, or being tied to particular legacy implementations)
access to low-level functions that cannot be portable, but that you sometimes need for implementing system utilities like
mount
,ifconfig
, etc.broken behavior for lots of POSIX-specified functions, where the GNU folks disagreed with the standards committee on how the functions should behave and decided to do their own thing.
As long as you're aware of these things, it should not be a problem to define _GNU_SOURCE
, but you should avoid defining it and instead define _POSIX_C_SOURCE=200809L
or _XOPEN_SOURCE=700
when possible to ensure that your programs are portable.
In particular, the things from _GNU_SOURCE
that you should never use are #2 and #4 above.
http://stackoverflow.com/questions/5582211/what-does-define-gnu-source-imply
为了这个问题折腾了好久,请问您现在的感受是什么?
“少侠,你还太年轻!”
- 诡异的_GNU_SOURCE宏
- 如何开启_GNU_SOURCE宏
- _GNU_SOURCE和__USE_GNU的差别
- _GNU_SOURCE-macro
- 好的事情诡异诡异诡异诡异英语
- 很诡异的Groovy
- 诡异的C程序
- 诡异的MSN
- 诡异的测试
- 诡异的Oracle
- 一个诡异的问题
- 诡异的Google输入法
- 诡异的JavaScript Closure
- 诡异的JavaScript Closure
- 诡异的程序
- 诡异的代码,郁闷~~~
- 诡异的TLB文件
- Python 的诡异代码
- GridView添加分页
- 慢慢的才知道的42件事
- 【算法学习】最优二叉查找树(动态规划)
- JavaBean生成数据库表
- muduo网络库学习之muduo_inspect 库涉及到的类
- 诡异的_GNU_SOURCE宏
- Virsual SVN
- 技术知识贴模板
- 谈谈对数据库连接方式的详细理解
- 网页出现二进制截断
- HDU 1856 More is better 并查集
- ubuntu上修改mysql默认字符编码出现的Job failed to start解决方法
- HD-SDI DVR发展与应用剖析
- strncpy strcpy