strange switch case problem
Code:
template<class T>
T GetValue<T>::get(TiXmlNode* pParent)
{
T attr;
if ( !pParent ) return attr;
TiXmlNode* pChild;
TiXmlText* pText;
int t = pParent->Type();
switch ( t )
{
case TiXmlNode::TINYXML_DOCUMENT:
break;
case TiXmlNode::TINYXML_ELEMENT:
attr =get_attribs(pParent->ToElement());
break;
case TiXmlNode::TINYXML_COMMENT:
break;
case TiXmlNode::TINYXML_UNKNOWN:
break;
case TiXmlNode::TINYXML_TEXT:
pText = pParent->ToText();
break;
case TiXmlNode::TINYXML_DECLARATION:
break;
default:
break;
}
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
get( pChild );
}
return attr;
}
A breakpoint at
case TiXmlNode::TINYXML_DOCUMENT:
break; // here
is never hit, why? It falls thru to the for loop straight off. The matching value is correct.
Thanks
Jack
Re: strange switch case problem
Quote:
Originally Posted by
lucky6969b
is never hit, why? It falls thru to the for loop straight off.
Well, if map and terrain don't match trust the terrain. :)
Re: strange switch case problem
Quote:
Originally Posted by
lucky6969b
A breakpoint at
case TiXmlNode::TINYXML_DOCUMENT:
break; // here
is never hit, why? It falls thru to the for loop straight off. The matching value is correct.
The term "fall through" has a very specific meaning in the context of switch statements. You should look it up.
What likely happens, is that the compiler implements the switch statement as a jump table and directly jumps to the next statement based on the value used in the switch. The break is only a control statement and doesn't really do anything, so it is skipped.