Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STLPort question

Reply
Thread Tools

STLPort question

 
 
A.L
Guest
Posts: n/a
 
      07-23-2003
Does STLPort have a problem with the standard string and assignment?
I am sure I am reading something incorrectly, but I don't know what:

Here is a summary of a few functions

_Self& append(_ForwardIter __first,
_ForwardIter __last,
forward_iterator_tag)
....
/* Get the length of the data we are assigning into the string */
const size_type __old_size = size();
difference_type __n = 0;
distance(__first, __last, __n);

/* If there is there is not enough room for it, then allocate and
copy. Otherwise just copy *.

if (__old_size + __n > capacity()) {
//Allocate and copy
}
else
{
//Copy
}

Now, all of that is fine. If the string is totally empty, then
(begin() and end() are both NULL) then we should allocate and copy.
The only problem is that the capacity function looks like this:

size_type capacity() const
{ return (_M_end_of_storage._M_data - _M_start) - 1; }

So, if the data is 0, and the start is 0, then we subract one and
return it. Unfortunately, the returntype is unsigned, so this becomes
a very large number. This causes the comparision against copy to
succeed when it should fail.

What am I missing?
 
Reply With Quote
 
 
 
 
Dan Cernat
Guest
Posts: n/a
 
      07-24-2003

"A.L" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
> Does STLPort have a problem with the standard string and assignment?
> I am sure I am reading something incorrectly, but I don't know what:
>
> Here is a summary of a few functions
>
> _Self& append(_ForwardIter __first,
> _ForwardIter __last,
> forward_iterator_tag)
> ...
> /* Get the length of the data we are assigning into the string */
> const size_type __old_size = size();
> difference_type __n = 0;
> distance(__first, __last, __n);
>
> /* If there is there is not enough room for it, then allocate and
> copy. Otherwise just copy *.
>
> if (__old_size + __n > capacity()) {
> //Allocate and copy
> }
> else
> {
> //Copy
> }
>
> Now, all of that is fine. If the string is totally empty, then
> (begin() and end() are both NULL) then we should allocate and copy.
> The only problem is that the capacity function looks like this:


If the string is empty, then begin() == end(). They are not null.

>
> size_type capacity() const
> { return (_M_end_of_storage._M_data - _M_start) - 1; }
>
> So, if the data is 0, and the start is 0, then we subract one and
> return it. Unfortunately, the returntype is unsigned, so this becomes
> a very large number. This causes the comparision against copy to
> succeed when it should fail.
>

Did you debug and saw that _M_end_of_storage._M_data and _M_start are 0? Or
you just assumed?

> What am I missing?


How about, what if _M_end_of_storage._M_data is 1 past the end of string?
Actually capacity tells you the _capacity_ not the _length_ of the string so
I think that even an empty string has a capacity > 0.

Hope it helped.

Dan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
spirit 1.6.0 stlport 4.6.2 msvc6 programmer_pete@yahoo.com C++ 2 01-27-2005 05:23 PM
Stlport linking errors with xlC on AIX pervinder C++ 1 09-24-2004 01:59 AM
Undefined symbol using STLport lib on AIX-4.3.3 John Graat C++ 0 08-26-2004 09:09 AM
STLPort 4.5.3 compiled with Comeau 4.3.0.1 on Windows? Icosahedron C++ 4 08-18-2003 04:47 PM
Problems compiling STLPORT 4.5.3 with g++ 3.3 Gary C++ 1 08-13-2003 07:18 AM



Advertisments