本文介绍了关于“如果”的问题声明...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想知道if

语句是否存在某种限制?我正在编写一个程序,需要同时检查一堆

条件(基本上)。而且我很确定

其余的程序工作得很好。我能想到的唯一一件事可能是错误的是,if语句只能在

本身中持有这么多值吗?让我展示一下我在做什么:


if(table001 [n [0]] [x [0]>> 5]& b [x [0] & 0x1f]!= 0&

table002 [n [1]] [x [1]>> 5]& b [x [1]& 0x1f]! = 0&&

table003 [n [2]] [x [2]>> 5]& b [x [2]& 0x1f]!= 0&& ;

...&&

table030 [n [29]] [x [29]>> 5]& b [x [29] & 0x1f]!= 0)

{

do_stuff();

} //结束如果

否则do_other_stuff();


我的问题是do_stuff从未被执行过。有30个不同的

表的int''我正在检查那里。我可以在

的未来使用更多,为了我的程序,我不想少用。我知道do_stuff应该执行因为我已经运行了测试用例

应该运行它。但它只是继续使用else

声明。我可能会偏离基础思维C是问题所在。如果你想要了解我的设置,那么它是:

WinXP,P4 1.8,编译器:DJGPP使用gcc v3.0.3


所以,我是否期望if语句过多?我是否错误地使用if

语句?任何有关这方面的建议或帮助都是非常感谢的。


-David C.

解决方案




您是否考虑过''if''的正文从未被执行过的可能性因为大而复杂事实上,条件是

* false *?您是否尝试在程序中运行''if''语句

,其中table001..030和b完全填充0x1f

值?在你的当前程序运行期间,这些表中存储了什么值?


[OT:你为什么还需要这么多表,以及为什么不要使用

afor循环检查所有这些,而不是将

数量的表格硬编码到你的程序中?]


-Arthur



[...]

if(table001 [n [0]] [x [0]> > 5]&(b [x [0]& 0x1f]!= 0)&&

....


Ralf





你是真的确定这是你想要进行的测试吗?


你有一个很长的表达式,包含三个不同的运算符(&,

!=, &&)每次使用很多次。既然你没有告诉编译器如何对它们进行分组,你基本上就是选择让编译器为你决定

。这通常不是一个好主意。



Hello all,

I was wondering if there were some sort of limitations on the "if"
statement? I''m writing a program which needs to check a bunch of
conditions all at the same time (basically). And I''m pretty sure the
rest of the program is working just fine. The only thing I could think
might be wrong is that the if statement can only hold so many values in
itself? Let me show what I''m doing:

if (table001[n[0]][x[0]>>5]&b[x[0]&0x1f] != 0 &&
table002[n[1]][x[1]>>5]&b[x[1]&0x1f] != 0 &&
table003[n[2]][x[2]>>5]&b[x[2]&0x1f] != 0 &&
... &&
table030[n[29]][x[29]>>5]&b[x[29]&0x1f] != 0)
{
do_stuff();
}//end if
else do_other_stuff();

My problem is that "do_stuff" is never executed. There are 30 different
tables of int''s I''m checking against up there. I could use more in the
future, and for the purposes of my program, I don''t want to use less. I
know that do_stuff should be executed because I have run test cases
where it should have been run. But it just keeps goin to the "else"
statement. I''m probably way off base thinking C is the problem. If you
want to know about my setup here it is:
WinXP, P4 1.8, Compiler: DJGPP using gcc v3.0.3

So, am I expecting too much out of the if statement? Am I using the if
statement incorrectly up there? Any advice or help in this regard is
greatly appreciated.

-David C.

解决方案



Have you considered the possibility that the body of the ''if'' is
never executed because the big complicated condition is, in fact,
*false*? Have you tried running the ''if'' statement in a program
in which "table001..030" and "b" are entirely filled with 0x1f
values? What values are stored in those tables during the run of
your current program?

[OT: And why do you need so many tables anyway, and why not use
a "for" loop to check all of them, rather than hard-code the
number of tables into your program?]

-Arthur



[...]

The formatting is a bit misleading. This is parsed as:

if (table001[n[0]][x[0]>>5] & (b[x[0]&0x1f] != 0) &&
....

Ralf




Are you REALLY sure that this is the test you want to be performing?

You have a really long expression containing three different operators (&,
!=, &&) used many times each. Since you have not told the compiler how to
group them, you are basically choosing to let the compiler make the decision
for you. This is frequently not a good idea.




这篇关于关于“如果”的问题声明...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 23:19
查看更多