如何用另一个定义使 if/else 预处理器宏无效?
How to void if/else preprocessor macro with another define?
假设我有一个c头文件test.h
// test.h
#ifdef A
int a;
#else
int b;
#endif
现在假设我想构建我的代码,如果定义了 B,则 a
和 b
都被定义。
有没有更聪明的方法而不是:
// test.h
#ifndef B
#ifdef A
int a;
#else
int b;
#endif
#else
int a;
int b;
#endif
?
谢谢
只需分别处理这两个变量并确定何时定义每个变量的逻辑:
#if defined(A) || defined(B)
int a;
#endif
#if !defined(A) || defined(B)
int b;
#endif
假设我有一个c头文件test.h
// test.h
#ifdef A
int a;
#else
int b;
#endif
现在假设我想构建我的代码,如果定义了 B,则 a
和 b
都被定义。
有没有更聪明的方法而不是:
// test.h
#ifndef B
#ifdef A
int a;
#else
int b;
#endif
#else
int a;
int b;
#endif
?
谢谢
只需分别处理这两个变量并确定何时定义每个变量的逻辑:
#if defined(A) || defined(B)
int a;
#endif
#if !defined(A) || defined(B)
int b;
#endif