gcc:error:case标签不会减少为整数常量 [英] gcc: error: case label does not reduce to an integer constant

查看:98
本文介绍了gcc:error:case标签不会减少为整数常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨再次,


这是我的问题:当我尝试编译下面包含

函数的代码时,我明白了:


-

gcc:21:错误:case标签没有减少到整数常量

gcc:24:错误:case标签不会减少到整数常数

-


现在,我(我认为我)理解错误,但是cryptMsg [i]肯定是

对我来说不是一个常数...


感谢您的帮助,

SysSpider


加密系统,虽然这对问题并不重要......

- 源代码 -

void decryptMsg(int sizeMsg){

int i;

char cryptMsg [sizeMsg],key [sizeMsg];


printf(&\\;输入加密的消息(无空格):");

scanf( "%s",cryptMsg);

printf("输入用过的密钥(无空格):");

scanf("%s",key);


printf(" \ n消息是:\ n");


for(i = 0;我< sizeMsg; i ++)

{

if(i%2 == 0&& i!= 0)printf("");


switch(cryptMsg [i])//这里开始问题

{

case charToInt(cryptMsg [i])< charToInt(key [i])://错误

printf("%d",charToInt(cryptMsg [i])+ 10 -

charToInt(key [i ]));

break;

case charToInt(cryptMsg [i])> = charToInt(key [i])://错误

printf("%d",charToInt(cryptMsg [i]) -

charToInt(key [i]));

break;

默认:

printf(" \ nError!\ n");

休息;

}

}

}

- 来源结束 -

Hi again,

This is my problem: when i try to compile the code that contains the
function below, i get this:

--
gcc:21: error: case label does not reduce to an integer constant
gcc:24: error: case label does not reduce to an integer constant
--

Now, I (think that I) understand the error, but cryptMsg[i] surely
doesn''t look like a constant to me...

Thanks for help,
SysSpider

P.S.: btw, for those interested, I''m implementing the "one time pad"
cryptography system, although that isn''t important to the problem...
--Source code--
void decryptMsg(int sizeMsg) {
int i;
char cryptMsg[sizeMsg], key[sizeMsg];

printf("\nEnter the encrypted message (no spaces): ");
scanf("%s", cryptMsg);
printf("Enter the used key (no spaces): ");
scanf("%s", key);

printf("\nThe message is:\n");

for(i = 0; i < sizeMsg; i++)
{
if(i%2 == 0 && i != 0) printf(" ");

switch(cryptMsg[i]) //Here starts the problem
{
case charToInt(cryptMsg[i]) < charToInt(key[i]): //Error
printf("%d", charToInt(cryptMsg[i]) + 10 -
charToInt(key[i]));
break;
case charToInt(cryptMsg[i]) >= charToInt(key[i]): //Error
printf("%d", charToInt(cryptMsg[i]) -
charToInt(key[i]));
break;
default:
printf("\nError!\n");
break;
}
}
}
--End of source--

推荐答案

Sy*************@hackernetwork.com ( SysSpider)写道:
Sy*************@hackernetwork.com (SysSpider) writes:
-
gcc:21:错误:case标签没有缩小为整数常量
gcc:24:error:case label does不减少到一个整数常数
-


大概是这条线和它下面类似的线:

case charToInt(cryptMsg [i] )< charToInt(key [i])://错误

现在,我(认为我)理解错误,但cryptMsg [i]肯定不会看起来像一个常数我...
--
gcc:21: error: case label does not reduce to an integer constant
gcc:24: error: case label does not reduce to an integer constant
--
Presumably for this line and the similar one below it:
case charToInt(cryptMsg[i]) < charToInt(key[i]): //Error
Now, I (think that I) understand the error, but cryptMsg[i] surely
doesn''t look like a constant to me...




完全正确。案例标签必须是整数常量。你不能用b / b
用switch语句做这种测试。我建议使用

if语句。

-

如果我告诉过你一次,我已经告诉过了你LLONG_MAX次不要夸大。

- 杰克克莱恩



Exactly. A case label must be an integer constant. You cannot
do this sort of test with a switch statement. I suggest using an
if statement instead.
--
"If I''ve told you once, I''ve told you LLONG_MAX times not to
exaggerate."
--Jack Klein


SysSpider写道:
SysSpider wrote:
嗨再次,

这是我的问题:当我尝试编译包含以下
函数的代码时,我得到了这个:

-
gcc:21:错误:case标签没有减少到整数常量
gcc:24:错误:case标签没有减少到整数常量
-

现在,我(认为我)理解错误,但cryptMsg [i]肯定对我来说看起来不是一个常数...

感谢您的帮助,SysSpider

PS:顺便说一句,对于那些感兴趣的人,我正在实施一次性密码加密系统,尽管这对于问题...

- 源代码 -
void decryptMsg(int sizeMsg){
int i;
char cryptMsg [sizeMsg],key [sizeMsg];

printf(" ; \ n输入加密的消息(无空格):");
scanf("%s",cryptMsg);
printf("输入用过的密钥(无空格):" );
scanf("%s",key);

printf(" \\\
The message is:\ n");

for (i = 0;我< sizeMsg; i ++)
{
if(i%2 == 0&& i!= 0)printf("");

switch(cryptMsg [i] )//这里开始问题
{char / case charToInt(cryptMsg [i])< charToInt(key [i])://错误
printf("%d",charToInt(cryptMsg [i])+ 10 -
charToInt(key [i]));
break;
case charToInt(cryptMsg [i])> = charToInt(key [i])://错误
printf("%d",charToInt(cryptMsg [i]) -
charToInt(key [i]));
break;
默认:
printf(" \ nError!\ n");
break;
}
}
}
- 来源结束 -
Hi again,

This is my problem: when i try to compile the code that contains the
function below, i get this:

--
gcc:21: error: case label does not reduce to an integer constant
gcc:24: error: case label does not reduce to an integer constant
--

Now, I (think that I) understand the error, but cryptMsg[i] surely
doesn''t look like a constant to me...

Thanks for help,
SysSpider

P.S.: btw, for those interested, I''m implementing the "one time pad"
cryptography system, although that isn''t important to the problem...
--Source code--
void decryptMsg(int sizeMsg) {
int i;
char cryptMsg[sizeMsg], key[sizeMsg];

printf("\nEnter the encrypted message (no spaces): ");
scanf("%s", cryptMsg);
printf("Enter the used key (no spaces): ");
scanf("%s", key);

printf("\nThe message is:\n");

for(i = 0; i < sizeMsg; i++)
{
if(i%2 == 0 && i != 0) printf(" ");

switch(cryptMsg[i]) //Here starts the problem
{
case charToInt(cryptMsg[i]) < charToInt(key[i]): //Error
printf("%d", charToInt(cryptMsg[i]) + 10 -
charToInt(key[i]));
break;
case charToInt(cryptMsg[i]) >= charToInt(key[i]): //Error
printf("%d", charToInt(cryptMsg[i]) -
charToInt(key[i]));
break;
default:
printf("\nError!\n");
break;
}
}
}
--End of source--




它不会像蜘蛛一样工作,给它与switch()。 C'的情况

没有表达。它需要一个常数。你需要提前知道

的案例。


开关(getnum()){

案例1 :有趣(1);休息;

案例2:有趣(2);休息;

默认:有趣(3);

}


规范的独家案例构造可以完成喜欢这个..


if(case1)

fun(1);

else if(case2)

fun(2);

else

fun(3);


...其中case1和case2表达式为0或不为0。

-

Joe Wright mailto:jo ******** @ comcast.net

所有东西都应尽可能简单,但不能简单。

---阿尔伯特爱因斯坦---



It won''t work your way Spider, give it up with switch(). C''s case
does not take an expression. It takes a constant. You have to know
in advance what the cases are looking for.

switch(getnum()) {
case 1: fun(1); break;
case 2: fun(2); break;
default: fun(3);
}

The canonical ''exclusive case'' construct can be done like this..

if (case1)
fun(1);
else if (case2)
fun(2);
else
fun(3);

...where case1 and case2 are expressions of 0 or not-0.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


Ben Pfaff< bl*@cs.stanford.edu>这样说:
Ben Pfaff <bl*@cs.stanford.edu> spoke thus:
案例标签必须是整数常量。
A case label must be an integer constant.




这与说案件相同标签必须有整数值

在编译时可计算,不是吗? (fmi)


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



That''s the same as saying that case labels must have integer values
computable at compile time, isn''t it? (fmi)

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于gcc:error:case标签不会减少为整数常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆