条件编译的几个写法备忘

就当笔记吧 / 2023-05-03 / 原文

判断有某个keyword

方式1,2

#ifdef COLOR_DEFAULT
    //...
#elif defined(COLOR_G)
    //...
#endif

方式3

#if COLOR_DEFAULT
    //...
#elif COLOR_G
    //...
#endif

 

判断没有某个keyword

方式1

#ifndef COLOR_DEFAULT
    //...
#endif

方式2

#if !defined(COLOR_DEFAULT)
    //...
#endif