侧边栏壁纸
  • 累计撰写 85 篇文章
  • 累计创建 16 个标签
  • 累计收到 1 条评论

C语言_跨平台宏定义

秋山人家
2021-11-15 / 0 评论 / 0 点赞 / 765 阅读 / 685 字
温馨提示:
本文最后更新于 2021-11-19,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

C语言跨平台宏定义

#ifdef 表示宏是否有定义,如果宏有定义则执行,否则不执行。后面常跟#else和#endif
#if 后跟常量整数表达式,如果表达式为非零值,则表达式为真,如果没有define(宏没有定义),也不不执行。后面常跟#elif #else #endif

#ifdef _WIN32
   //define something for Windows (32-bit and 64-bit, this part is common)
   #ifdef _WIN64
      //define something for Windows (64-bit only)
   #else
      //define something for Windows (32-bit only)
   #endif
#elif __APPLE__
    #include "TargetConditionals.h"
    #if TARGET_IPHONE_SIMULATOR
         // iOS Simulator
    #elif TARGET_OS_IPHONE
        // iOS device
    #elif TARGET_OS_MAC
        // Other kinds of Mac OS
    #else
    #   error "Unknown Apple platform"
    #endif
#elif __ANDROID__
    // android
#elif __linux__
    // linux
#elif __unix__ // all unices not caught above
    // Unix
#elif defined(_POSIX_VERSION)
    // POSIX
#else
#   error "Unknown compiler"
#endif
0

评论区