开发者

Comparing pointers fails mystically in VC++

I have a tree structure and I want to find all nodes matching a given criteria. Each time I call the find function, it returns next matching node. Children are searched by recursive function call.

For some reason a key comparison of pointers fails for this implementation. Please see the code below, I have pointed out the failing comparison.

HtmlTag* HtmlContent::FindTag(string tagName, string tagParameterContent)
{
    if (tagName.empty() && tagParameterContent.empty())
        return NULL;

    if (this->startTag == NULL)
        return NULL;

    this->findContinue = this->FindChildren(this->startTag, &tagName, &tagParameterContent);
    return this->findContinue;
}

HtmlTag* HtmlContent::FindChildren(HtmlTag* firstTag, string* tagName, string* tagParameterContent)
{
    HtmlTag* currentTag = firstTag;
    HtmlTag* childrenFound = NULL;

    while (currentTag != NULL)
    {
        if (!tagName->empty() && *tagName == currentTag->tagName)
        {
            if (tagParameterContent->empty() || currentTag->tagParameters.find(*tagParameterContent, 0) != -1)
            {
                if (this->findContinue == NULL)
                    break; // break now when found
                else if (this->findContinue == currentTag) // TODO why this fails?
                    this->findContinue == NULL; // break on next find
            }
        }

        if (currentTag->pFirstChild != NULL)
   开发者_StackOverflow     {
            childrenFound = this->FindChildren(currentTag->pFirstChild, tagName, tagParameterContent);
            if (childrenFound != NULL)
            {
                currentTag = childrenFound;
                break;
            }
        }

        currentTag = currentTag->pNextSibling;
    }

    return currentTag;
}

VC++ compiler accepts this code but for some reason I can't put a breakpoint on this comparison. I guess this is optimized out, but why? Why this comparison fails?


I think that you shoud replace == with = in assignment after comparison. Compiler optimalized this whole section because it doesnt do anything useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜