#define STR_A abc
#if STR_A == abc //I want to make some check here
do something A
#else
do something B
#endif
STR_Aが定義したものを確認できますか?
#define STR_A abc
#if STR_A == abc //I want to make some check here
do something A
#else
do something B
#endif
STR_Aが定義したものを確認できますか?
STR_A
トークンに定義されているかどうかを確認したい場合abc
(それ自体は別のマクロであってはなりません)、いくつかのトリックを手伝うことができます
#define STR_A_TESTER_abc 1
#define CONCAT(A, B) A ## B
#define STR_A_TESTER CONCAT(STR_A_TESTER_, STR_A)
#if STR_A_TESTER
// do whatever
#else
// or other
#endif
これは、オペレーティングシステムを区別しようとすると非常に多く発生します。
同じことがSTR_Aにも使用できます。
#if defined(STR_A)
# if (STR_A == "abc")
// do something
# else
// do something else
# endif
#else
#warning "STR_A has not been defined."
#endif