S
Stefan Ram
In the following example:
{ const char * concat =( stdstring + stdstring_ ).c_str(); ... }
it seems that the value of c_str() is a pointer to a
temporary char array. Now, that POINTER is used to
initialize the variable »concat«.
There might be a rule that a temporary can be used to
initialize an object with automatic storage duration, and
then the lifetime of that temporary is extended to the
lifetime of that automatic object.
But what about the temporary char ARRAY pointed to by the
pointer »concat«? Is there a rule that extends its lifetime
too? After all, it is not the same as the POINTER to it,
so another rule would be needed to extend its lifetime too.
So, can »concat« safely (portably) be dereferenced in this
block to get access to the concatenation of the C++-strings
as a C-string?
{ const char * concat =( stdstring + stdstring_ ).c_str(); ... }
it seems that the value of c_str() is a pointer to a
temporary char array. Now, that POINTER is used to
initialize the variable »concat«.
There might be a rule that a temporary can be used to
initialize an object with automatic storage duration, and
then the lifetime of that temporary is extended to the
lifetime of that automatic object.
But what about the temporary char ARRAY pointed to by the
pointer »concat«? Is there a rule that extends its lifetime
too? After all, it is not the same as the POINTER to it,
so another rule would be needed to extend its lifetime too.
So, can »concat« safely (portably) be dereferenced in this
block to get access to the concatenation of the C++-strings
as a C-string?