Re: basic_string causes crash in _vsnprintf???
- From: "Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom>
- Date: Thu, 23 Jun 2005 15:29:18 +0100
> Thanks. Was just doing internet searches and found the same thing, that
does
> in fact work. The problem is we have a half million lines of code that
was
> using stlport and that worked in stlport.
You should _NEVER_ code because it sort of ..."works".
You should code because it is "correct". Correct according to C++ standard.
No "undefined behaviour" - a technical term according to the standard.
Correct code is more maintainable. You shift compiler vendor it should still
work even if the vendors implementation is different under the hood.
Even if you 500,000 lines of code that "work" but it turns out that it is
just an accident that "work", you should make an effort to correct the lines
of code. It is an error to write code in C++ that relies on some aspect of
"undefined behaviour" working the way you expect. I regard this as so severe
that I would correct it immediately, even 500,000 lines of code. And I would
fire programmers that write "undefined behaviour" code, particularly if it
turns out there is a decent alternative which works with _ALL_ compilers.
In the case of std::string, getting a pointer to the internal buffer of
characters means that member function c_str() should be called. And note
this is constant so you should never attempt to write to that buffer - it is
read-only.
> So the question is how to avoid
> having to do that for every string everywhere in the code. Not sure all
code
> would be compatible if a changed everything to a CString instead of a
> tstring... anyone run into this before?
CString allows you to do that operation.
But these days, implicit conversion operators are frowned on for classes.
Better to have explicit named conversions - like std::string - less
unexpected nasty surprises
Stephen Howe
.
- Follow-Ups:
- References:
- basic_string causes crash in _vsnprintf???
- From: WXS
- Re: basic_string causes crash in _vsnprintf???
- From: Hendrik Schober
- Re: basic_string causes crash in _vsnprintf???
- From: WXS
- basic_string causes crash in _vsnprintf???
- Prev by Date: Re: basic_string causes crash in _vsnprintf???
- Next by Date: Re: basic_string causes crash in _vsnprintf???
- Previous by thread: Re: basic_string causes crash in _vsnprintf???
- Next by thread: Re: basic_string causes crash in _vsnprintf???
- Index(es):
Relevant Pages
|