[gameprogrammer] Re: Is this valid?
- From: Paulo Pinto <pjmlp@xxxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 25 Jan 2008 12:00:04 +0000
Hi,
If you want to avoid endless hours looking for
pointer problems, NEVER try to do this kind of tricks.
They aren't garanteed to be portable at all.
Cheers,
Paulo
Quoting Brian <brian.ripoff@xxxxxxxxx>:
I don't believe that the C++ standard specifies that std::string is
contiguous. From the SGI std::string page (I know it isn't the
standard itself, but its close:
http://www.sgi.com/tech/stl/basic_string.html) they say:
Note that the C++ standard does not specify the complexity of
basic_string operations.
If std::string was guaranteed to be contiguous std::string::operator[]
could be specified as an O(1) operation.
In practise though, most implementations appear to make std::string a
contiguous dynamic array of some sort.
On Jan 25, 2008 7:24 AM, Olivier Delannoy <olivier.delannoy@xxxxxxxxx> wrote:
However you can write something like
std::string s;
s.assign(strlen("Hello world"), '\0');
strcpy(&s[0], "Hello world");
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Is this valid?
- From: Olivier Delannoy
- References:
- [gameprogrammer] Is this valid?
- From: Kevin Jenkins
- [gameprogrammer] Re: Is this valid?
- From: Matthew Weigel
- [gameprogrammer] Re: Is this valid?
- From: Olivier Delannoy
- [gameprogrammer] Re: Is this valid?
- From: Brian
Other related posts:
I don't believe that the C++ standard specifies that std::string is contiguous. From the SGI std::string page (I know it isn't the standard itself, but its close: http://www.sgi.com/tech/stl/basic_string.html) they say:
Note that the C++ standard does not specify the complexity of basic_string operations.
If std::string was guaranteed to be contiguous std::string::operator[] could be specified as an O(1) operation. In practise though, most implementations appear to make std::string a contiguous dynamic array of some sort. On Jan 25, 2008 7:24 AM, Olivier Delannoy <olivier.delannoy@xxxxxxxxx> wrote:
However you can write something like
std::string s;
s.assign(strlen("Hello world"), '\0');
strcpy(&s[0], "Hello world");
--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] Re: Is this valid?
- From: Olivier Delannoy
- [gameprogrammer] Is this valid?
- From: Kevin Jenkins
- [gameprogrammer] Re: Is this valid?
- From: Matthew Weigel
- [gameprogrammer] Re: Is this valid?
- From: Olivier Delannoy
- [gameprogrammer] Re: Is this valid?
- From: Brian