evaluation order of expressions in gcc
Mon Mar 29 11:38:00 GMT 2004
i could not find an answer to this question on the net so i'm posting it
as far as i know, the Ansi C standard does not specify the order of
evaluation of expression arguments. so if i wrote:
x = f() + g()
it would be up to the compiler whether f() or g() would be called first.
my question is, does anybody know how does the current version of gcc choose
whether to call f() or
g() first? on which optimization options does this depend, if any?
after making a few experiments, it looks like gcc usually does left-to-right
evaluation (first calls f() and then g()). so i would like to know in which
cases (if any) this would not be true. or if this information is not known
for the current version, then for any previous version would also be
to clarify: i am not interested in the evaluation order of arguments to a
function call, or left vs right side of an assigment. also i am not interested
in expressions involving pre- or post- increment or decrement or anything
such. i understand that these may be a problem. so my question is only regarding
function calls in expressions with normal arithmetic (also pointer
arithmetic) and compare operators.
+++ NEU bei GMX und erstmalig in Deutschland: TÃV-geprÃ¼fter Virenschutz +++
100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz
More information about the Gcc-help