7

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

5

_POSIX_C_SOURCE makes different functionality available.

_POSIX_C_SOURCE 1 makes the functionality from the POSIX.1 standard available. _POSIX_C_SOURCE 2 makes the functionality from the POSIX.2 standard available. _POSIX_C_SOURCE 199309L makes the functionality from the POSIX.1b standard 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.

wovano
  • 4,543
  • 5
  • 22
  • 49
gj13
  • 1,314
  • 9
  • 23
  • 1
    What do you mean by "not caring for specific POSIX standard compliance"? Isn't it the other way around, i.e. _enforcing_ specific POSIX standard compliance? – einpoklum Feb 11 '19 at 08:06