我在交换机的一个案例中使用了预定义的 char 变量,并收到此错误 case label does not reduce to an integer
char player = 'X';
switch(.....){
case player:
.
.
.
.
我需要一个解决方案。
最佳答案
来自C11 standard :
The expression of each case label shall be an integer constant expression
player
不是“常量表达式”。
请注意,在 C 中将变量限定为 const
,是否不使其成为 C 意义上的“常量表达式”标准。
标签要么需要是整数文字,要么是枚举
,实际上是一个整数。
关于c - 在 switch 的情况下使用定义的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673956/