首页 > 代码库 > 宏的几个特殊的使用

宏的几个特殊的使用

功能一:简单的替换、预处理等

功能二:#ifndef/#define/#endif 防止头文件重复引用

功能三:连接

#define CONNECTION(_x,_y) _x##_yINT a     = CONNECTION(1024);     // a = 1024STRING s  = CONNECTION("Lu","key"); // s = "Lukey"

功能四:转换成char

#define CONVERT_TO_CHAR(_x) #@_xCHAR c = CONVERT_TO_CHAR(1);   // c = ‘1‘

功能五:转换成String

#define CONVERT_TO_STR(_x) #_xSTRING a = CONVERT_TO_STR(1);      //a = "1"enum TEST{  TEST_T_01,  TEST_T_02,}STRING b = CONVERT_TO_STR(TEST.TEST_T_02); //b = "TEST_T_02"