tag:blogger.com,1999:blog-4370268061829710124.post3845825887002963492..comments2024-03-06T03:36:43.359-06:00Comments on Robert Fisher: Thinking out loud (3.0): C++ temporariesRoberthttp://www.blogger.com/profile/16733274876782876659noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-4370268061829710124.post-86651579576006768312009-09-08T10:32:02.227-05:002009-09-08T10:32:02.227-05:00I should probably give credit to Coverity for flag...I should probably give credit to Coverity for flagging this error and explaining it. (Although “explain” is being generous.)Roberthttps://www.blogger.com/profile/16733274876782876659noreply@blogger.comtag:blogger.com,1999:blog-4370268061829710124.post-12343985297002342772009-09-08T09:49:03.415-05:002009-09-08T09:49:03.415-05:00Since we can rewrite it to eliminate the temporari...Since we can rewrite it to eliminate the temporaries, that may argue that a sufficiently advanced compiler could do so as well. On the other hand, since C++ ctors and dtors can have side-effects, such an optimization could change the meaning of some programs.<br /><br />That may be a topic for another post.<br /><br />As for c_str, yes, you have to be careful with it. It’s best to avoid it when possible, but when you can’t, it does what you need. How would you have it work?<br /><br />(Why does Blogger feel the need to prevent <code> or <tt> in comments? >_<)Roberthttps://www.blogger.com/profile/16733274876782876659noreply@blogger.comtag:blogger.com,1999:blog-4370268061829710124.post-13102231288529916912009-09-08T07:21:16.403-05:002009-09-08T07:21:16.403-05:00Wait. "the temporary variables that the compi...Wait. "the temporary variables that the compiler must generate". Do you mean "must" as in "this is surely what is going on" or "must" as in "there is no other way to implement this"? I think it's an implementation error that the original code did not work. Am I wrong? It looks like c_str() is returning a pointer that cannot actually be used reliably.Craig Weekshttps://www.blogger.com/profile/06150881989038836595noreply@blogger.com