This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Enforcing order of execution for function arguments


"Chris Jefferson" <chris@bubblescope.net> writes:

> One thing which comes up regularly in various C and C++ messageboards
> is that statements like "f() + g()" and "a(f(), g())" do not declare
> which order f() and g() will be executed in.
> 
> How hard would it be to fix the order of execution in gcc/g++? Could
> someone point me to the piece of code which must change, or if it is
> only a very small change, the actual change required? I would very
> much like to be able to benchmark this, as I can find no previous case
> where someone has tried fixing the order of execution to see if it
> actually makes any measureable difference.

It would be a bit tedious but not especially difficult.  My idea would
be to rewrite c = a + b into t1 = a; t2 = b; c = t1 + t2.  Of course
this rewriting could be skipped where a and b are constants or simple
variables.  This would be done in the frontend.

In fact you could do this rewriting outside of the compiler in a
source-to-source transformation tool.

> Would anyone be interested in this being added as a command line argument?

No.  We should only create a variant language for a good reason.  This
is not a good reason.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]