Topic: Q: why not a Side effect qualifier ?
Author: jlm@two-oo-one.fr (Jean-Louis Moser)
Date: 1995/10/20 Raw View
On october 13, I asked:
| is A a = 100; equivalent to A a (100); ?
If I well understand the different threads the answer is NO.
A a = 100 is known as copy initialization and may or not require
Copy constructor depending on compilers optimizations which can be
different from a compiler to an other, but without taking in account
copy constructor side effect.
Why C++ methods an functions could not be qualified as having "SideEffect".
This could enable compilers to make more and predictable optimizations.
Suppose this stupid code:
| #include "A.h"
| A a;
| int x = a.val() + a.val();
If this code doesn't know A::val implementation, that is, A interface is
in A.h and A implementation in A.cc, A::val() will be called twice even
A::val() is a const method, because compiler can not see the implementation
of A::val() which can be:
{return 1;} (no side effect)
or
{return global_var++;}
The Side Effect property would be inherited by any function or method
which would have in its body a Side Effect function or method. global
or static variable affect, I/O would be Side Effect functions.
what about this ?
jlm
--
+----------------------------+------------------------------------+
| Jean-Louis Moser | 2001 SA |
| tel: 33 (1)46.66.54.54 | 2, rue de la renaissance |
| Email: jlm@two-oo-one.fr | F-92184 Antony Cedex |
+----------------------------+------------------------------------+
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]