Topic: Unnecessary ctor call removed?
Author: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Date: 1999/02/26 Raw View
Code:
class Something { ... };
void f(Something s)
{
...
}
int main()
{
Something test;
// Here comes the question
f(Something(test));
}
Question: Can I be *SURE* that a new Something won't be unnecessarily
created? Or put another way: will the code generated for
'f(Something(test))' be exactly the same as for 'f(test)'?
Please note that f takes its parm by value.
Andrei
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
Date: 1999/02/26 Raw View
"Andrei Alexandrescu" <alexandrescua@micromodeling.com> writes:
----------------
| Code:
|
| class Something { ... };
| void f(Something s)
| {
| ...
| }
| int main()
| {
| Something test;
| // Here comes the question
| f(Something(test));
| }
|
| Question: Can I be *SURE* that a new Something won't be unnecessarily
| created? Or put another way: will the code generated for
| 'f(Something(test))' be exactly the same as for 'f(test)'?
----------------
The short answer is *NO*.
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]