Re: Libstdc++ problems
Re: Libstdc++ problems
- Subject: Re: Libstdc++ problems
- From: Steve Checkoway <email@hidden>
- Date: Mon, 26 Feb 2007 12:20:47 -0800
On Feb 26, 2007, at 11:30 AM, Mike Linden wrote:
I seem to be running into some problems with my configuration of
Xcode and
the Standard C++ Library.
Which version of g++ are you using?
The symptom of the problem shows up when I try to use the 'string'
class,
and specifically when I use the 'c_str()' method to access the 'C'
string of
the class. It always returns a pointer to the beginning of the class
structure +1. The address of the 'C' string appears to be at the
head of the
structure and if I cast that as a pointer to a char* I see the string.
However, 'c_str()' neither casts it or even points to the correct
address,
its off by 1. This I can work around by using '.data()' instead,
which at
least returns the correct address.
The +1 is correct. From the header:
* A string looks like this:
*
* @code
* [_Rep]
* _M_length
* [basic_string<char_type>] _M_capacity
* _M_dataplus _M_refcount
* _M_p ----------------> unnamed array of char_type
* @endcode
*
* Where the _M_p points to the first character in the string, and
* you cast it to a pointer-to-_Rep and subtract 1 to get a
* pointer to the header.
Both c_str() and data() return the same thing:
const _CharT*
c_str() const
{ return _M_data(); }
const _CharT*
data() const
{ return _M_data(); }
where _M_data() returns _M_dataplus._M_p.
The other symptom I see is an exception being thrown anytime the
'.replace()' method is called, since this is used in other methods
such as
'.substr()' I can't work around this.
I wonder if you've been trying to modify the string by hand and have
overwritten the header.
--
Steve Checkoway
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden