条件编译对于枚举与宏的处理因何不同,了解编译请进入
vc6.0编译器,对于如下条件编译,
#if WM_BYTE_ORDER == BIG_ENDIAN
cout << "big endian" << endl;
#else
cout << "little endian" << endl;
#endif
如果用宏来定义,如下,则条件编译测试正确。
#define BIG_ENDIAN 0
#define LITTLE_ENDIAN 1
如果用枚举来定义,如下,
enum
{
BIG_ENDIAN = 0,
LITTLE_ENDIAN = 1
};
则无论是
#define WM_BYTE_ORDER BIG_ENDIAN或是
#define WM_BYTE_ORDER LITTLE_ENDIAN,都只编出if下面的条件,即始终输出"big endian"。
请高手知道 c 预编译 枚举 宏
[解决办法]
The preprocessor runs before the compilation begins. The result of preprocessing is single file which is then passed to the actual compiler.
预处理在编译之前,所以你的enum不管用。