why is "timer_t" defined in "time.h" on Linux but not OS X

Unix and C have an intertwined history, as they were both developed around the same time at Bell Labs in New Jersey and one of the major purposes of C was to implement Unix using a high level, architecture independent, portable language. However, there wasn't any official standardization until 1983. POSIX, the "portable operating system interface" is an IEEE operating system standard dating back to the time of the "Unix Wars". It has been evolving ever since and is now the most widely implemented such standard. OSX is officially POSIX compliant, and linux unofficially is -- there are logistics and costs associated with official compliance that linux distros do not partake in.

Much of what POSIX has focussed on is the elaboration of things not part of ISO C. Time.h is, but the ISO version does not include the timer_t type or any functions which use it. Those are from the POSIX extension, hence this reference in the linux header:

#if !defined __timer_t_defined && \
((defined _TIME_H && defined __USE_POSIX199309)

The __USE_POSIX199309 is an internal glibc symbol that is set in features.h when _POSIX_C_SOURCE >= 199309L, meaning that POSIX.1b is to be supported (see the feature_test_macros manpage). This is also supported with _XOPEN_SOURCE >= 600.

are there any differently defined functions or attributes between different OS?

I think with regard to C, amongst POSIX systems, there is an effort to avoid that, but it does happen. There are some GNU extensions (e.g. sterror_r()) that have incompatible signatures from their POSIX counterparts. Possibly this happens when POSIX takes up the extension but modifies it, or else they are just alternatives dreamed up by GNU -- you can opt for one or the other by using an appropriate #define.


timer_t is used by the timer_ APIs in POSIX, such as timer_create(). In the UNIX 03 version of POSIX, those are an optional part of POSIX, and macOS didn't implement it. Linux and Solaris, and possibly some other UN*Xes, did.

So the code you were looking at might work on Linux and Solaris, but won't work on macOS, unless Apple implements the timer APIs in the future. (They're part of the current version of the POSIX specification, so Apple will have to do so if they want to conform to version 4, rather than version 3, of the specification.)

Tags:

Linux

C

Darwin