strange switch case problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: strange switch case problem

  1. #1
    Join Date
    Dec 2010
    Posts
    601

    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
    Last edited by lucky6969b; December 28th, 2012 at 01:31 AM.

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: strange switch case problem

    Quote Originally Posted by lucky6969b View Post
    is never hit, why? It falls thru to the for loop straight off.
    Well, if map and terrain don't match trust the terrain.

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,013

    Re: strange switch case problem

    Quote Originally Posted by lucky6969b View Post
    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.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center