I am just going through some code and have come across an #ifdef
that is:
#ifdef __MACH__ #define CLOCK_REALTIME 0 int clock_gettime (int /*clk_id*/, struct timespec *t) { struct timeval now; int rv = gettimeofday(&now, NULL); if (rv) return rv; t->tv_sec = now.tv_sec; t->tv_nsec = now.tv_usec * 1000; return 0; } #endif
What does __MACH__
refer to here? Is it an arbitrary name for "machine" which references the current OS I am compiling on? That's really the only thing I can think of it being.
__MACH__
is (due to the pair of leading underscores) an identifer reserved by the standard for use by the implementation.__MACH__
in particular is one of the macros defined by implementations targeting Apple unix operating systems (OSX, iOS, and Darwin). The name is based on the "Mach Kernel", which is central to those operating systems.__MACH__
is not defined for older (non-unix) Apple operating systems. All (supported) Apple systems may be detected using the__APPLE__
macro, so one test for iOS/OSX/Darwin is#if defined(__APPLE__) && defined(__MACH__)
– Peter