简体   繁体   中英

How and when should I use _POSIX_C_SOURCE in C programs?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM