Re: basic_string causes crash in _vsnprintf???



> 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


.



Relevant Pages

  • Re: basic_string causes crash in _vsnprintf???
    ... Was just doing internet searches and found the same thing, ... >>> CString has always worked this way and microsoft code I believe ... > not implicitly called when a CString is passed to a vararg function. ... > So again the OP is relying on internal layout details. ...
    (microsoft.public.vc.stl)
  • Re: basic_string causes crash in _vsnprintf???
    ... Was just doing internet searches and found the same thing, ... >> CString has always worked this way and microsoft code I believe uses it ... > internal layout of the string class. ... the OP is relying on internal layout details. ...
    (microsoft.public.vc.stl)
  • Re: Is the first character in a string a letter?
    ... white space. ... I've been searching the doc and the internet but can't find anything. ... If you are using CString then there is TrimLeft. ...
    (microsoft.public.dotnet.languages.vc)