Menu

Strange behavior with static lib

Anonymous
2004-05-21
2004-05-26
  • Anonymous

    Anonymous - 2004-05-21

    At first many thanks for the great tinyxml !
    I've encountered a problem when using tinyxml in a static lib.

    example:
    <?xml version="1.0" encoding="ISO-8859-1"?>
      <theroot>
        <!--Copyright: -->
        <Vendor name="vendor1">
          <System name="A"> 
          </System>
       </Vendor>
       <Vendor name="vendor2">
          <System name="B"> 
          </System>
       </Vendor>
    </theroot >

    I use this for searching the first vendor:

    TiXmlNode*    next = 0;
    TiXmlElement* elem = 0 ;

    for( next= root->FirstChild(); next; next=next->NextSibling(nodename) )
    {
    if(elem = next->ToElement()) {
          cout << endl << "attr: " << elem->Attribute("name");
            if( elem->Attribute(name)==attrval )
                break;
        }
      }

     
    • Anonymous

      Anonymous - 2004-05-21

      At first many thanks for the great tinyxml !
      I've encountered a problem when using tinyxml in a static lib.

      example:
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <theroot>
      <!--Copyright: -->
      <Vendor name="vendor1">
      <System name="A">
      </System>
      </Vendor>
      <Vendor name="vendor2">
      <System name="B">
      </System>
      </Vendor>
      </theroot >

      I use this for searching the first vendor:
      nodename=vendor;
      attrname=name;
      attrval=vendor1;

      TiXmlElement* SearchNode(TiXmlNode* root, string& nodename, string& attrname, string& attrval)
      {
      TiXmlNode* next = 0;
      TiXmlElement* elem = 0 ;

      for( next= root->FirstChild(); next; next=next->NextSibling(nodename) )
      {
        if(elem = next->ToElement()) {
          if( elem->Attribute(attrname)==attrval )
            break;
        }
      }
      return elem;
      }

      Everything works fine as long as I use tinyxml by adding the cpp files to my project.
      When using a static lib the function returns the second! vendor-node, and there also acccess violations with other functions.
      I've tried various TLib and compiler options when building the library with no success.
      (Borland BCB4)

      Any ideas? Thank you

      W.Johann

       
      • B Sizer

        B Sizer - 2004-05-26

        All I would say is that this is a prime example of when to use a debugger. With a small data file like this it should be practical to single-step through the code and see what's going wrong. You could even try printing out some details of each TiXmlNode as you loop through them to see what is being processed.

        You're also mixing a lot of pointers and references in there. It's possible you're trashing one of the pointed-to objects somewhere along the line. You don't change nodename, attrname, or attrvalue, so they may as well be passed by value anyway, or at least by const reference.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.