CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Detecting the target operating system platform

Similarly, at compile-time we can determine the operating system platform for which we're compiling (note, if we're cross-compiling, this will not be our native platform).

Based on this information we can conditionally report an inability to support specific platforms, or can include our own implementation of functions not otherwise available.

#ifdef _WIN64
   //define something for Windows (64-bit)
#elif _WIN32
   //define something for Windows (32-bit)
#elif __APPLE__
    #include "TargetConditionals.h"
    #if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR
        // define something for simulator   
    #elif TARGET_OS_IPHONE
        // define something for iphone  
    #else
        #define TARGET_OS_OSX 1
        // define something for OSX
    #endif
#elif __linux
    // linux
#elif __unix // all Unix-derived systems not detected above
    // Unix
#elif __posix
    // POSIX
#else
    #error unrecognized operating system platform
#endif

 


CITS2002 Systems Programming, Lecture 22, p5, 16th October 2023.