Abdelrazak Younes <[EMAIL PROTECTED]> writes: Angus> Hmmm. How does your example differ from mine?
Angus> char const * using_this_returned_value_is_undefined_behaviour() Angus> { Angus> char const * cdata = std::string("data").c_str(); Angus> return cdata; Angus> } Angus> The lifetime of std::string::c_str() is no longer than the lifetime of Angus> std::string... Angus> How does QByteArray overcome that? Abdel> It's not QByteArray specifically but char * instead of char const *. Abdel> AFAIK, char * is a C-string and the temporary allocated memory will stay Abdel> allocated for that C-string if the temporary object disappear. Abdel> This is not true when you use a char const *. Abdel> "char *" is a strange hybrid beast in C and by extension in C++. Abdel> Now, this is perhaps non standard but I am quite sure this will work Abdel> with gcc and VC++. I could be wrong on ll the line though... LOL! I think You are. You've confused this with "const &" std::string normal_lifetime = std::string("boring"); std::string const & the_same_lifetime_as_boring = std::string("boo"); // The compiler won't allow this... std::string & an_illegal_binding = std::string("ahh"); Angus