http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: Is this valid?



According to the books of Herb Sutter, it is safe and standard
compliant to do so. Indeed, std::string and std::vector are specified
to be contiguous and are well suited for this kind of manipulation.
Nevertheless, I agree that this kind of code are best avoided.


On Jan 25, 2008 1:00 PM, Paulo Pinto <pjmlp@progtools.org> wrote:
> 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@gmail.com>:
>
> > 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@gmail.com> 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
>
>
>



-- 
Olivier Delannoy
Ph.D. Student
PRiSM Laboratory
Versailles University, FRANCE

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html