How and when should I use _POSIX_C_SOURCE in C programs?

放肆的年华 提交于 2019-12-19 03:11:16

问题


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?

To generalize, I suppose I'm asking: When and under what conditions should _POSIX_C_SOURCE be used?


回答1:


_POSIX_C_SOURCE makes different functionality available.

_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

Higher values like 200809L make more features available. (man 7 feature_test_macros)

In general _POSIX_C_SOURCE is needed if you need strict POSIX compliance

It is safe to define it in every project if you don't care for specific POSIX standard compliance.



来源:https://stackoverflow.com/questions/48460942/how-and-when-should-i-use-posix-c-source-in-c-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!