在C程序中应如何以及何时使用_POSIX_C_SOURCE? [英] How and when should I use _POSIX_C_SOURCE in C programs?
问题描述
我已经不得不维护一些C项目,该项目也应该在较旧的平台上进行编译.目前,对于某些平台,已定义宏_POSIX_C_SOURCE
.我在想-定义它是否可以接受,我是否应该在所有平台上不总是定义它?也许具有最高的相关价值?
I've gotten myself into having to maintain some C project which should also compile on older platforms. At the moment, for some platforms, the macro _POSIX_C_SOURCE
is defined. I was wondering - if it's acceptable to have it defined, should I not just define it always, on all platforms? And perhaps with the highest relevant value?
概括地说,我想问的是:_POSIX_C_SOURCE
何时何地应在什么条件下使用?
To generalize, I suppose I'm asking: When and under what conditions should _POSIX_C_SOURCE
be used?
推荐答案
_POSIX_C_SOURCE
提供了不同的功能.
_POSIX_C_SOURCE 1
使POSIX.1标准中的功能可用
_POSIX_C_SOURCE 2
使POSIX.2标准中的功能可用
_POSIX_C_SOURCE 199309L
使POSIX.1b标准中的功能可用
_POSIX_C_SOURCE 1
makes the functionality from the POSIX.1 standart available
_POSIX_C_SOURCE 2
makes the functionality from the POSIX.2 standart available
_POSIX_C_SOURCE 199309L
makes the functionality from the POSIX.1b standart available
更高的值(如200809L)使更多功能可用. (第7人,feature_test_macros)
Higher values like 200809L make more features available. (man 7 feature_test_macros)
通常,如果您需要严格遵守POSIX,则需要_POSIX_C_SOURCE.
如果您不关心特定的POSIX标准合规性,则可以在每个项目中对其进行定义.
It is safe to define it in every project if you don't care for specific POSIX standard compliance.
这篇关于在C程序中应如何以及何时使用_POSIX_C_SOURCE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!