What are the possible values of _POSIX_TIMERS?

519 Views Asked by At

The posixoptions manpage shows that the following macros can be used to determine the degree of a host's support for the posix timers API:

  • _POSIX_TIMERS
  • _POSIX_CPUTIME
  • _POSIX_THREAD_CPUTIME
  • _POSIX_CLOCK_SELECTION
  • _POSIX_MONOTONIC_CLOCK

On my dev system (Ubuntu-based Linux distro, using gcc 7.5.0), _POSIX_TIMERS evaluates to 200809, _POSIX_CPUTIME to 0, and _POSIX_THREAD_CPUTIME to 0.

I have been searching for more information on these macros, but can't seem to find the needed information. I would like to know where they are defined (in a header file? or "magically" by the compiler?), and what the possible values of _POSIX_TIMERS are.

However, I did run across some C code which compared _POSIX_TIMERS to another constant starting with 2012. So obviously various different values must be possible.

2

There are 2 best solutions below

1
On BEST ANSWER

The POSIX definition (2018 edition) says that:

_POSIX_TIMERS

The implementation supports timers. This symbol shall always be set to the value 200809L.

It's defined in the <unistd.h> header.

0
On

When defined (by the implementation—not you), these feature test macros expand to an integral constant of type long.

If undefined or 0L, the feature is not supported. Otherwise the value is YYYYMM, indicating the year and month of the respective standard's publication.

The idea is that developers can use conditional compilation to test for the presence of a particular feature, in a particular version or set of versions. And to make it future-proof, so developers can express "I need at least the 2012 version of this feature, 2008 is not enough".