vy********@kono nenko.net (Vyacheslav Kononenko) wrote:
All,
If I am not mistaken I had some problems with code like this:
std::string foo, bar;
...
somefunc( foo.c_str(), bar.c_str() );
Problem was that c_str() used buffer shared btw instances of
std::string in that implementation. I did not find anything that
standart would explicitly say about this case. So what would you say?
If foo and bar contain the same string, then you could get the
same buffer, eg:
foo = bar = "hello";
then ( foo.c_str() == bar.c_str() ) is possible.
When writing 'somefunc' you should allow for this possibility.
Also if the strings overlap you could (conceivably -- I don't
know of any implementation that actually does this) get the
same buffer:
foo = "rhombus";
bar = "bus";
then ( foo.c_str() + 4 == bar.c_str() ) could possibly be true.
However the standard requires that the result of c_str() is
valid for a certain time, so if the strings are different and
you get the same buffer, your implementation is broken.