Ifdef in C using cross-platform Android / iOS platform not working properly

I have a piece of code for changing calls between different platforms. But I found a problem using iphone and ipad, the definition of TARGET_OS_IPHONE only works with iphone, but there is no ipad, I don’t want to try another one to think it is an ipad, because maybe this will be a source of problems in the future.

I lost 2 days looking for a color issue in the opencv matrix caused by this .....

My question is: is there a right solution to execute part of the code in iOS SO (Iphone AND Ipad)?

As a link, I always look at this link.

Code selection example:

#ifdef __linux__ 
    // All linux arch
#elif _WIN32
    // Windows 32 and 64
#elif __APPLE__
    #ifdef TARGET_OS_IPHONE
         // iOS, no work with iPAD
    #elif TARGET_IPHONE_SIMULATOR
        // iOS Simulator
    #elif TARGET_OS_MAC
        // Other kinds of Mac OS
    #else
        // Unsupported platform
    #endif
#elif __ANDROID__
  // Android all versions
#else
  //  Unsupported architecture
#endif
+4
1

"TargetConditionals.h" "__APPLE__". , Apple.

, , :

#ifdef __linux__ 
// All linux arch
#elif _WIN32
// Windows 32 and 64
#elif __APPLE__
    #include "TargetConditionals.h"     // <--- Include this
    #ifdef TARGET_OS_IOS                // <--- Change this with a proper definition
    // iOS, including iPhone and iPad
    #elif TARGET_IPHONE_SIMULATOR
    // iOS Simulator
    #elif TARGET_OS_MAC
    // Other kinds of Mac OS
    #else
    // Unsupported platform
#endif
#elif __ANDROID__
// Android all versions
#else
//  Unsupported architecture
#endif

, TARGET_OS_IPHONE, "TARGET_OS_IOS" .

, : '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr//TargetConditionals.h".

+4

Source: https://habr.com/ru/post/1626011/


All Articles