After clearing string, it gets filled with ???

Started by
8 comments, last by RPTD 19 years, 4 months ago
I have a string that contains: "models/monsters/imp/imp" When I call string.clear(), or try to assign anything else to the string, it gets filled with garbage and shows up as ??? in the debugger.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
Advertisement
Programming language? Which compiler? Which debugger?
spontanous i can only think of the clear function to create an empty string placing the pointer to this empty string in the string-object. as your debugger most probably examines the string the old pointer points to it will show as ???, meaning the pointer is no more valid.

try examining the new string pointer after the clear function.

Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

VS .NET, std::string, C++.

Nope, the pointer has valid data
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
What happens when you do:

string = "";
Same thing, ???.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
im prety sure ??? just means unknown.. the dubugger does this for me all the time.
FTA, my 2D futuristic action MMORPG
Yes, well I'd like to know why it's unknown when I'm passing it valid data...
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
More than likely, your std::string implementation knows when it's getting a string of length 0, just deletes any string it currently has, doens't reset the pointer to zero, and just sets teh length field to 0 and ignores the pointer until you add something into the string.

In other words, it might be working perfectly. (edit: oh yeah. And this is the reason there's an abstraction barrier around the internals. You're not supposed to care what goes on inside.)
yeah... until you need a 'char*' to feed it into a printf or such a thing... and bang you've got a SEGF because the pointer is nonense instead of set to NULL... hm... that's a rather lame implementation though.

Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

This topic is closed to new replies.

Advertisement