使用Visual Studio 2010在C语言中使用宏来切换语句

Yos*_*fki 0 c macros visual-studio-2010

我正在尝试做这样的事情

#define GETCART1 0;
#define GETCART2 1;

void helper(int *Array,int length,int counter, int option){
    if (length > counter){
        switch(option){
        case (GETCART1) :

            break;
        }//switch
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到编译错误,当我更换GETCART1使用0其作品的罚款.这是为什么?

cni*_*tar 7

从定义中删除分号.

#define GETCART1 0;
                  ^ Drop this
Run Code Online (Sandbox Code Playgroud)

如果不这样做,那么在预处理器完成之前,您的代码最终将如下所示:

switch(option){
case (0;) :
       ^
    break;
}
Run Code Online (Sandbox Code Playgroud)