Thread: std::string: Has my compiler gone nuts??

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    Exclamation std::string: Has my compiler gone nuts??

    To the Pros out there:

    Hy, im searching for a bug since 2 days, and i asked a lot of pros in my company, but nobody could help me.
    Heres the situation:

    Visual Studio Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600)

    I had a project with a strange bug, so i could melt down the problem into this simple program (I took the original Project and
    deleted file after file to look when it would go correctly) and still got the strange behaviour.

    heres the whole program, its a .vcproj-file project with 1 source file called main.cpp where the following is inside:

    Code:
    #include <string>
    
    
    class EventTest
    {
    public:
    
      EventTest (int a_id, const std::string& a_text);
    
      int m_Id;
      std::string m_Text;
    };
    
     /*inline*/ EventTest::EventTest (int a_id, const std::string& a_text)
        : m_Id(a_id)
        , m_Text(a_text)
    
     {
       //m_Id = a_id;
       //m_Text = a_text;
     }
    
    
    int main(int argc, char** argv)
    {
      EventTest test(1, "Text");
      //std::string strTest = "TEST";
    
      return 0;
    }

    there are also some additional Dependencies in the Properties, but i wont mention it here.


    The result when debugging it is extremely strange. its about the content of m_Text who is (watched with debugger) always
    something like "0,0,0,0,T,e,x,t,-b,4,0,0,0,d,4,....." (and signs i cant write here) and so on with a string size of _MySize = 14220893!! instead of 4.

    As soon as i use a variable of type std::string (the line that is commented now) all works fine!!!

    I can make the behaviour the other way round as well: make the constructor inline, or initialize the members in the body. when doing either of the two, then the program works only correct (having "Text" in the string) when NOT having the variable of type std::string in the code!!

    I made an other new project (not deleting things from the original project) with exactly the same code, the same project settings, and the same Dependencies. And this program is ALWAYS working correctly!!! but i cant find any difference, its like magic.
    also the output (wich dlls are loaded) is the same.

    The program would acctually work finde only this std::string in the class is nasty!

    Does anybody has an idea? or a tipp how to analyze the problem further??

    Im sure it is some strange sideeffect, but of what??

    thanx for any input!

    andreas

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You never described what the problem is. You say you're seeing weird values in the debugger. At what point? When do things go wrong?

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Does anybody has an idea?
    There's nothing wrong with your code. I'd guess it's a corrupted and/or unchanged build. Try cleaning the solution and rebuilding it. If the problem keeps occurring then you've already found your solution: ditch the project and create a new identical one.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    what fails is initialisation

    The problem occurs right directly after initialisation of the object (after the only line, this class is used). i tryed rebuild, clean etc many many times before, but it does not help. how can this strange behaviour of (only) the std::string class be influenced?

    thanx

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's strange behaviour - a compiler bug or something similar. It's therefore out of the reach of normal C++.

    If it works in a new project, then just delete the current one.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    I think i found the problem, but why?

    Hello, i just realised, that when i delete the file vc80.idb (minimum rebuild dependency File)
    in the same folder as the .vcproj file is, the thing is working correctly!! in all my experiments i always copied the whole project and changed it, so i also copied the vc80.idb, wich is not deleted after a rebuild all.

    But i also found out, that the problem can occur again, and then i have to delete the file again.

    any clue what the reason can be?


    andreas

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No, and really, it doesn't matter. It's not like it's under your control.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    - See if there is a service pack available.
    - Send a bug report to Microsoft as a complete small repeatable example.
    - Search MSDN to see if the issue is known, and if there is a better workaround.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    630
    Can you try:

    Code:
    #include <string>
    
    
    class EventTest
    {
    public:
    
      EventTest (int a_id, const std::string a_text);
    
      int m_Id;
      std::string m_Text;
    };
    
     /*inline*/ EventTest::EventTest (int a_id, const std::string& a_text)
        : m_Id(a_id)
        , m_Text(a_text)
    
     {
       //m_Id = a_id;
       //m_Text = a_text;
     }
    
    
    int main(int argc, char** argv)
    {
      EventTest test(1, "Text");
    
      return 0;
    }

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    What you can do is check the differences between the projects itself. Maybe one project has constructor inlining turned on or something which causes the weird behaviour.

    try to ask in a visual C++ related newsgroup and search MSDN. If its a compiler bug then there is a chance somebody else stumbled onto it too

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. This compiler is driving me nuts
    By martin_00 in forum C Programming
    Replies: 32
    Last Post: 12-31-2002, 03:25 PM