case标签不会减少为整数常量 [英] case label does not reduce to an integer constant
问题描述
嗨!我是C的新手,我从GCC 4.0收到错误,并且
跟随函数:
unsigned int search_for_clo_tag(const unsigned char * array,const
unsigned int array_element){
unsigned char clo_tag;
unsigned int i;
unsigned char ope_tags [1];
switch(*(array + array_element)){
case''('' ':
clo_tag =''''';
* ope_tags =''['';
>
*(ope_tags + 1)=''{'';
休息;
case''['' :
clo_tag ='']'';
* ope_tags =''('';
*(ope_tags + 1)=''{'';
休息;
case''{'':
clo_tag =''}'';
* ope_tags =''('';
*(ope_tags + 1)=''['';
bre ak;
}
for(i = 1; *(array + array_element + i)!=''\''' ; i ++)
switch(*(array + array_element + i)){
case *(array + array_element):case * ope_tags :case *(ope_tags + 1):
if(!must_be_ignored(array,array_element + i))
i = search_for_clo_tag(array, array_element + i) - array_element;
休息;
case clo_tag:
if( !must_be_ignored(array,array_element + i))
返回array_element + i;
休息;
}
}
错误是:案例标签不会减少到整数常量和
它与第二个开关有关。我不明白为什么会这样,
因为字符是整数,对吧?
嗯,希望你能帮助我。谢谢,祝你好运!
PS:对不起我的英文。我来自阿根廷,:P
Hi! I''m pretty new to C and I''am getting an error from GCC 4.0 with the
following function:
unsigned int search_for_clo_tag (const unsigned char *array, const
unsigned int array_element) {
unsigned char clo_tag;
unsigned int i;
unsigned char ope_tags[1];
switch (*(array + array_element)) {
case ''('':
clo_tag = '')'';
*ope_tags = ''['';
*(ope_tags + 1) = ''{'';
break;
case ''['':
clo_tag = '']'';
*ope_tags = ''('';
*(ope_tags + 1) = ''{'';
break;
case ''{'':
clo_tag = ''}'';
*ope_tags = ''('';
*(ope_tags + 1) = ''['';
break;
}
for (i = 1; *(array + array_element + i) != ''\0''; i++)
switch (*(array + array_element + i)) {
case *(array + array_element): case *ope_tags: case *(ope_tags + 1):
if (!must_be_ignored (array, array_element + i))
i = search_for_clo_tag (array, array_element + i) - array_element;
break;
case clo_tag:
if (!must_be_ignored (array, array_element + i))
return array_element + i;
break;
}
}
The error is: "case label does not reduce to an integer constant" and
its related to the second switch. I don''t understand why this happen,
since chars are integers, right?
Well, hope you can help me. Thank you and good luck!
PS: Sorry my English. I''am from Argentina, :P
推荐答案
adelfino写道:
[ ...]
adelfino wrote:
[...]
switch(*(array + array_element + i)){
case *(array + array_element):case * ope_tags:case *(ope_tags + 1 ):
这些情况都不是整数常量
[...]
case clo_tag:
也不是这一个
错误是:案例标签不会减少到整数常量和它相关的第二个开关。我不明白为什么会这样,
因为字符是整数,对吗?
switch (*(array + array_element + i)) {
case *(array + array_element): case *ope_tags: case *(ope_tags + 1):
none of these cases are integer constants
[...]
case clo_tag:
nor is this one
The error is: "case label does not reduce to an integer constant" and
its related to the second switch. I don''t understand why this happen,
since chars are integers, right?
那又怎样?变量不是常量。
So what? variables are not constants.
哦,我明白了。
现在我将不得不弄明白如何做这样的事情/>
变量。
谢谢Martin!
Oh, I get it.
Now I will have to figure out how to do something like that without
variables.
Thank you Martin!
adelfino写道:
adelfino wrote:
哦,我明白了。
现在我必须弄清楚如何在没有
变量的情况下做这样的事情。
谢谢Martin!
Oh, I get it.
Now I will have to figure out how to do something like that without
variables.
Thank you Martin!
我更喜欢切换案例中的'else if'模型。这样的东西..
if(expr1)
do1();
else if(expr2)
do2();
else if(expr3)
do3();
else
DO0(); / *当所有其他方法都失败时* /
-
Joe Wright
所有事情都应尽可能简单,但并不简单。
---阿尔伯特爱因斯坦---
I prefer the ''else if'' model to the switch cases. Something like this..
if (expr1)
do1();
else if (expr2)
do2();
else if (expr3)
do3();
else
do0(); /* when all else fails */
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
这篇关于case标签不会减少为整数常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!