0
votes

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.

1
apparently it refers to Mac OSX , you should find it is defined by the build system or perhaps even by the compilerM.M
__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

1 Answers

0
votes

__MACH__ is a built in compiler macro that indicates if you are on Macintosh operating system. It is defined when compiling on a mac machine.