&是什么QUOT;#定义_GNU_SOURCE"意味着? [英] What does "#define _GNU_SOURCE" imply?

查看:182
本文介绍了&是什么QUOT;#定义_GNU_SOURCE"意味着?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我不得不使用基本名()功能,而男子3基名here )给了我一些奇怪的消息:

Today I had to use the basename() function, and the man 3 basename (here) gave me some strange message:

备注

有两种不同版本的基名()的的 - 在 POSIX 上述版本,并在 GNU版本,之后,一个得到

There are two different versions of basename() - the POSIX version described above, and the GNU version, which one gets after

的#define _GNU_SOURCE 结果
  的#include<&string.h中GT;

我不知道这是什么的#define _GNU_SOURCE 表示:这是的污点的的code我用GNU样写许可?或者它只是用来告诉编译器像的好了,我知道,这组函数是不是POSIX,因此不便于携带,但我想无论如何要使用它的。

I'm wondering what this #define _GNU_SOURCE means: is it tainting the code I write with a GNU-like license? Or is it simply used to tell the compiler something like "Well, I know, this set of functions is not POSIX, thus not portable, but I'd like to use it anyway".

如果是这样,为什么不给,而不必定义一些模糊的环境变量得到一个函数实现或其他人不同的页眉,?

If so, why not give people different headers, instead of having to define some obscure environment variable to get one function implementation or the other?

东西也是我的错误:编译器如何知道哪些功能实现与可执行链接?是否使用的#define 以及

Something also bugs me: how does the compiler know which function implementation to link with the executable? Does it use this #define as well?

任何人有一些指点我?

推荐答案

定义 _GNU_SOURCE 无关凭许可证和一切与写作(非)便携式$ C $℃。如果定义 _GNU_SOURCE ,您将获得:

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:


  1. 获得大量的非标准的GNU / Linux的扩展功能

  2. 访问权限,从POSIX标准省略传统功能(通常有很好的理由,如替换为更好的选择,或者被捆绑到特定的传统实现)

  3. 获得低级别的功能,即不能随身携带,但有时需要实现系统的实用工具,比如安装使用ifconfig

  4. 破碎行为大量POSIX指定的函数,其中,GNU乡亲标准委员会不同意的职能应该如何表现,决定做自己的事情。

只要你意识到这些东西,它不应该是一个问题来定义 _GNU_SOURCE ,但是你应该避免定义它,而是定义 = _POSIX_C_SOURCE 200809L _XOPEN_SOURCE = 700 时,可确保你的程序是可移植的。

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.

特别是,从 _GNU_SOURCE 的事情,你应该的从不的使用是#2和#以上4。

In particular, the things from _GNU_SOURCE that you should never use are #2 and #4 above.

这篇关于&是什么QUOT;#定义_GNU_SOURCE"意味着?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆