关于解析以下if else条件 [英] About parsing the following if else condition

查看:73
本文介绍了关于解析以下if else条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if((type == vhpiCompInstStmtK)||(type == vhpiRootInstK))

if(reason)* reason =" Object is a scope" ;;

否则如果(原因)

* reason =" object is not writable";

这里其他将被视为第二个if或者第一个

如果。


我现在不想调试GCC。但就是这样,需要一些大括号才能获得



if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.

I dont want to debug GCC now. But just that, need some braces to get
across it .

推荐答案

pa ******** @ hotmail.com 写道:

if((type == vhpiCompInstStmtK)||(type == vhpiRootInstK))

if(reason)* reason =" Object is a scope" ;;

否则如果(原因)

* reason =" object is not writable" ;;


这里其他地方将被视为第二个if或者for第一个

如果。


我现在不想调试GCC。但就是这样,需要一些支撑才能获得


if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.

I dont want to debug GCC now. But just that, need some braces to get
across it .






- -

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


pa********@hotmail.com 写道:
pa********@hotmail.com wrote:

if((type == vhpiCompInstStmtK)||(type == vhpiRootInstK))

if(reason)* reason ="对象是一个范围;

else if(reason)

* reason =" object is not writable";


在这里,否则将被视为第二个if或者第一个

if。
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";
Here the else will be treated as the else for 2nd if or for the first
if.



如果你想问一个问题,最好将你的帖子短语

作为一个问题。


我假设您的问题是哪个'如果''上面代码中的''else''

对应于?"

''else''将与第二个''if''相关,所以我读代码

可以用缩进和括号表示: -


if((type == vhpiCompInstStmtK)||(type == vhpiRootInstK)){

if(reason){

* reason = 对象是范围;

}否则如果(原因){

* reason =" object is not writable";

}

}


这显然不是一段有用的代码。


我认为你的意图是表示为: -


if((type == vhpiCompInstStmtK)||(type == vhpiRootInstK)){

if(reason){

* reason ="对象是范围和现状t ;;

}

}否则{

if(reason){

* reason =" object是不可写的;

}

}


有些大括号当然可以被移除......

If you want to ask a question, it would be good to phrase your posting
as a question.

I assume your question is "which ''if'' will the ''else'' in the code above
correspond to?"

The ''else'' will relate to the second ''if'' so my reading of the code
could be expressed with indentation and braces as this :-

if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK)) {
if (reason) {
*reason = "Object is a scope";
} else if (reason) {
*reason = "object is not writable";
}
}

which is clearly not a useful piece of code.

I think your intent would be expressed as :-

if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK)) {
if (reason) {
*reason = "Object is a scope";
}
} else {
if (reason) {
*reason = "object is not writable";
}
}

Some of the braces could, naturally, be removed...


10月3日16:22,parag_p ... @ hotmail.com < parag_p ... @ hotmail.com>

写道:
On 3 Oct, 16:22, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:

if((type == vhpiCompInstStmtK)||(type = = vhpiRootInstK))

if(reason)* reason =" Object is a scope" ;;

else if(reason)

* reason =对象不可写;


如果或者第一个

if,其他将被视为第二个的else。


我现在不想调试GCC。但就是这样,需要一些支撑来获得它的b $ b。
if ((type == vhpiCompInstStmtK) || (type == vhpiRootInstK))
if (reason) *reason = "Object is a scope";
else if (reason)
*reason = "object is not writable";

Here the else will be treated as the else for 2nd if or for the first
if.

I dont want to debug GCC now. But just that, need some braces to get
across it .



这是一个很好的例子,说明为什么没有

括号的条件语句是邪恶的。作为维护程序员,我肯定会在代码审查时将上述代码返回给作者。通过缩进或类似方式运行

代码,您将立即看到

编译器将如何解析它。

This is an excellent example of why conditional statements without
braces are evil. As a maintenance programmer myself I would certainly
throw the above code back to the author at code review time. Run the
code through indent or similar, and you''ll immediately see how the
compiler will parse it.


这篇关于关于解析以下if else条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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