宏定义搭配##,引用时遇到报错does not give a valid preprocessing token,请教下如何解决
程序代码:
typedef struct { char eLogState; char *pcPassword; } CFG_LOG_T; typedef struct { unsigned int Enable; unsigned char Func; unsigned int LevelNum; const unsigned int *pLevelTab; } CFG_ADC_T; typedef struct { CFG_LOG_T CFG_LOG_TO; CFG_ADC_T CFG_ADC_TO[4]; } CFG_SDK_T; CFG_SDK_T const *GetSDKConfig(void); #define GET_SDK_CFG(type_) ((type_ *)(&(GetSDKConfig()->type_##O))) static CFG_SDK_T gstSDKConfig = { .CFG_LOG_TO = { .eLogState = 1, .pcPassword = "123456", }, .CFG_ADC_TO[0] = { .Enable = 1, .Func = 1, .LevelNum = 3, .pLevelTab = ADC_DataLevelTab, }, .CFG_ADC_TO[1] = { .Enable = 1, .Func = 1, .LevelNum = 3, .pLevelTab = ADC_DataLevelTab, }, .CFG_ADC_TO[2] = { .Enable = 1, .Func = 1, .LevelNum = 3, .pLevelTab = ADC_DataLevelTab, }, .CFG_ADC_TO[3] = { .Enable = 0, .Func = 1, .LevelNum = 3, .pLevelTab = ADC_DataLevelTab, }, }; int main (int argc, char *argv[]) { //这样调用没问题 if (GET_SDK_CFG(CFG_LOG_T)->eLogState == 1) { } 这样调用会报错 pasting "]" and "O" does not give a valid preprocessing token if(GET_SDK_CFG(CFG_ADC_T[0])->Func == 1) { } return 0; }