While循环未按预期运行 [英] While Loop Not acting as expected

查看:100
本文介绍了While循环未按预期运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码片段仍然让我感到困惑. (它是扫描仪的一部分,我将循环的其余部分显示为contex.
GetChar(char& ch)在EOF处返回-1,在错误时返回FALSE,在成功时返回TRUE.

The following Code fragment still baffles me. (It is part of a scanner, and I show the rest of the loop just as contex.
GetChar(char& ch)returns -1 at EOF, FALSE on Error,TRUE on success.

while((bRes=GetChar(ch))==TRUE)


即使GetChar返回-1(EOF)也会继续.
最近几个小时我一直在盯着它.






continues even when GetChar returns -1 (EOF).
I''ve been staring at this for the last few hours.





// Get the Char Already Scanned as First Char of the Token
CString Tmp=Tok.m_sTokenString;

// Now keep Scanning until EOF or Non Lexical Char
while((bRes=GetChar(ch))==TRUE){
    TOKEN_CHAR tc=ClassifyTokenChar(ch);
    if((tc==TC_LEXICAL)||(tc==TC_NUMERICAL)){
        Tmp+=ch;
        continue;
    }
    else{
        UnGetChar(ch);
        break;
    }
}

推荐答案

如何定义GetChar(ch),返回值的类型是什么~~~
How did you define the GetChar(ch),what''s the return value''s type~~~


好,解决了.

该问题到达类CScanner,它是CParser的基类,而CParser是CDbScriptParser的基类.通过极大的巧合,CParser中的未初始化的Var(指针)破坏了堆栈到,将While循环中的值从-1设置为1.
接受我的道歉,希望此帖子的任何贡献者都永远不会发生! (我也知道,这对我们大多数人都是虔诚的希望).当心,当这种巧合发生时,您会以为您的大脑着火了!逻辑似乎不再适用.是的,在Restrospect中,我应该知道这是与堆栈相关的问题.有时应该允许一个人Panick.

我发现它的方法是单步执行生成的汇编代码.

活动的道德:阅读目标处理器汇编语言的知识将很有帮助.

感谢所有人!


布拉姆.
Well, Resolved.

The Issue arrived in class CScanner, which is base class to CParser, which is Base Class to CDbScriptParser. An UnInitialised Var (pointer)in CParser clobbered the Stack To, by Great Coincidence set the value in the While Loop from -1 to 1.
Accept my apologies, I hope it will never happen any of the contributors to this post! (I also know that this is a veign hope for most of us). Beware all, when such coincidence happens, you will think you''re brain is on fire! Logic does not seem to apply anymore. And Yes, I Should have known, in Restrospect, that this was a Stack Related Issue. Sometimes one should be allowed to Panick.

The way I found it, was by single stepping through the lines of generated assembler code.

Moral of the Event: It is helpfull to have a reading knowledge of the Target Processors Assembly Language.

Thanks to All!


Bram.


尝试在EOF上返回FALSE.
FALSE为0.
TRUE不为0.
Try to return FALSE on EOF.
FALSE is 0.
TRUE is not 0.


这篇关于While循环未按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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