Re: basic_string causes crash in _vsnprintf???

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Jeff F wrote:
> "Hendrik Schober" <SpamTrap@xxxxxx> wrote in message
> news:evNBWU$dFHA.2880@xxxxxxxxxxxxxxxxxxxxxxx
>> WXS <WXS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>>> 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. 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 has always worked this way and microsoft code I believe
>>> uses it all
>>> over the place like that.
>>>
>>> Any ideas to help migration?
>>
>> Whether or not this works depends entirely on the
>> internal layout of the string class. 'CString' is
>> intentionally written so that this works, but
>
> I assume you're referring to CString's operator LPCTSTR(). Which is
> not implicitly called when a CString is passed to a vararg function.
> So again the OP is relying on internal layout details.

Yes, but intentional, documented details. The CString implementation goes
to great pains to make (effectively) reinterpret_cast to const char* "work"
specifically so that CStrings can be used with printf-like functions.

-cd


.



Relevant Pages

  • Re: basic_string causes crash in _vsnprintf???
    ... Was just doing internet searches and found the same thing, ... No "undefined behaviour" - a technical term according to the standard. ... CString allows you to do that operation. ... implicit conversion operators are frowned on for classes. ...
    (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)