Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 658
einpoklum Avatar asked Jan 26 '18 11:01

einpoklum


1 Answers

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

like image 56
gj13 Avatar answered Oct 26 '22 11:10

gj13