How and when should I use _POSIX_C_SOURCE in C pro

2019-02-17 08:20发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-17 08:53

_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.

查看更多
登录 后发表回答