【发布时间】:2011-08-13 14:10:45
【问题描述】:
#include <stdio.h>
int main(int argc, char *argv[]){
char a = 'c';
switch('c'){
case a:
printf("hi\n");
}
return 0;
}
上面的代码不会为这个错误编译:
case label does not reduce to an integer constant
为什么不允许这样做?
【问题讨论】:
-
我认为您只能在
switch中使用常量 - 请参阅 cprogramming.com/tutorial/c/lesson5.html,第二个示例。 -
@Jonny:我相信他知道这一点。他在问为什么会这样——为什么 C 语言被设计为只允许常量?
标签: c switch-statement compiler-construction