Re: CString help



On Mon, 25 Jun 2007 00:26:54 -0700, "Mihai N." <nmihai_year_2000@xxxxxxxxx>
wrote:

The following will be fine:

string s;
s.resize(n);
memset(&s[0], 0, n);

One of the benefits to requiring s[0] to return a real reference (which is
what disallows COW) is that &s[0] returns a real pointer.

From wat I know works in all current implementations, but still not
*guaranteed* by the standard in any way.

This is going 'round in circles. :) You've restated what I said at the
beginning:

<q>
Practically speaking, you can do this:

const int N = 100;
std::string s;
s.resize(N);
int len = WindowsAPI(&s[0], N);
s.resize(len);

Though not guaranteed, I don't know any implementation where this won't
work. (I'd really like the non-contiguity, reference-counted, etc options
to just go away. People who need those things can't do without them, and
the possibility they exist complicates things for everyone else.)
</q>

I later posted a link to this proposal, whose adoption guarantees this
currently univerally supported behavior:

530. Must elements of a string be contiguous?
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#530

In my previous message, I was responding to your comment about "After
reading your open-std.org link..." to give you an example of the sort of
things it makes kosher. I could have posted my earlier example instead,
because it's the same thing. Besides completing the circle, your latest
reply is a great example of what I meant by, "the possibility they exist
complicates things for everyone else." Even after I started by saying it's
non-standard, though TTBOMK universally supported, then posted a link to a
document that indicates it will become standardized, you came back with,
"it's not standard". Like I said, going 'round in circles. :)

Bottom line: Unless you want to reserve the possibility of replacing
std::string with flex_string or whatever, you should feel free to go ahead
and use the technique I presented, which comes in really handy when dealing
with Windows APIs. You should even feel good about it. :)

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: Can anyone help me with some German?
    ... I'm managing to find a lot of them, but am stuck on "Flag." ... in the middle with the edge of the palm while plucking with the thumb of the same hand, rapidly pulling the hand away so the two halves of the string are left ringing in opposite phase with the middle of the string largely not moving at all. ... This effect sounds a shade over an octave higher in pitch than the string's fundamental, and it's often written for the plucked string, sounding an octave higher. ... Tiny open circles will usually be marked above--or sometimes below--the note. ...
    (rec.music.classical)
  • Re: HOW DO YOU WALK FROM ONE CHORD TO THE NEXT?
    ... written the "circles of fifths". ... Look at the sequence of notes between the root note of the chord you're playing and the next. ... Then the fifth string open. ... second fret. ...
    (alt.guitar.beginner)
  • Re: Using =address to provide address location for =average
    ... but you need to use INDIRECT to convert the string ... created from ADDRESS to a real reference. ... >the average function. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: CString help
    ... One of the benefits to requiring sto return a real reference (which is ... what disallows COW) is that &sreturns a real pointer. ...
    (microsoft.public.vc.mfc)