On Sat, May 06, 2006 at 01:10:08PM +0300, Martin Vermeer wrote: > char const * using_this_returned_value_is_undefined_behaviour() > { > char const * cdata = std::string("data").c_str(); > return cdata; > } > > I think I understand this. The problem is that cdata is made to point to > the start of the string "data" in memory, which is a constant that may > be allocated in two different ways: > > 1) like a local variable inside the using_...vior() routine, i.e., part > of the instantiation's stack frame; > > 2) as part of the _code_ of this routine. > > In the first case, the stack frame disappears on return, and using > whatever cdata used to point to may or may not bite you. In the second, > the string "data" is a permanent part of the executable binary. > > const-ing *cdata may for some compilers influence this behaviour, who > knows. > > Does this make sense?
Right, the outcome of undefined behaviour tends to depend on circumstances. You are scetching very likely outcomes. Andre'