2

(split this off from this question)

The following 3 macros appear in many C source files which try to detect/rely on the availability of POSIX functionality:

  • _POSIX_SOURCE
  • _POSIX_C_SOURCE
  • _POSIX_ (and _POSIX ?)

In the linked-to question it's explained that we're supposed to set _POSIX_C_SOURCE to the POSIX version on which we want to rely (although setting it doesn't guarantee that the functionality will actually be available - that's up to the compiler/OS). Also, while I can set it as the user, it's not clear when others set it themselves (e.g. the compiler / build system). For the other two, I know neither when I should set them nor when others set them.

So, what is the difference in meaning between the three macros? When would each of them be set for me? And why/when should I choose to set one of them over the others, if at all?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • It's a lot to go through, but [here is the official POSIX reference online](http://pubs.opengroup.org/onlinepubs/9699919799/). The *Base Definitions* chapter, section 2 (Conformance) contains the definition for `_POSIX_C_SOURCE`. You can also use the reference to search for specific functions and see what macros they might need. – Some programmer dude Feb 11 '19 at 08:20

1 Answers1

2

Very partial answer (and with thanks to @SomeProgrammerDude):


The POSIX reference tells us that:

The POSIX.1-1990 standard specified a macro called _POSIX_SOURCE. This has been superseded by _POSIX_C_SOURCE.

and in practical terms, the GNU C library manual tells us, for example:

The state of _POSIX_SOURCE is irrelevant if you define the macro _POSIX_C_SOURCE to a positive integer.

and it should probably be the same for other C standard library implementations. So - never use _POSIX_SOURCE yourself, only use _POSIX_C_SOURCE (except if you are on old platforms where the OS and libraries have not seen updates for the past 20 years at least).


_POSIX_ and _POSIX is a Microsoft-Visual-C(++)-specific macro. I am guessing you define it to get MSVC to expose POSIX/POSIX-like functionality. According to this non-authoritative thread on the MinGW mailing list, MSVC no longer uses _POSIX_ (and _POSIX?) as of MSVC2013.

einpoklum
  • 118,144
  • 57
  • 340
  • 684