K
kalita
The expression:
(a + b) * (c + d) * (e + f)
Could be evaluated in the two following ways, among others (in polish
notation):
a b + c d + * e f + *
or
a b + c d + e f + * *
The former way is "better" in a sense that it requires only 2
temporaries, while the latter requires 3. If a, b, c etc. are all of
the same user defined type, can I rely on the compiler to use any
specific order of evaluation? Or is it implementation defined?
I'm asking because it seems to me that it is possible to evaluate any
C++ expression involving objects of the same type using only 2
temporaries, but only if compiler choses the optimal order. Otherwise
number of temporaries needed may be arbitrarily high.
cheers.
M.
(a + b) * (c + d) * (e + f)
Could be evaluated in the two following ways, among others (in polish
notation):
a b + c d + * e f + *
or
a b + c d + e f + * *
The former way is "better" in a sense that it requires only 2
temporaries, while the latter requires 3. If a, b, c etc. are all of
the same user defined type, can I rely on the compiler to use any
specific order of evaluation? Or is it implementation defined?
I'm asking because it seems to me that it is possible to evaluate any
C++ expression involving objects of the same type using only 2
temporaries, but only if compiler choses the optimal order. Otherwise
number of temporaries needed may be arbitrarily high.
cheers.
M.