Re: evaluation order of expressions in gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



laura_rand@xxxxxxxxxxxxxxxxx writes:

> > > i could not find an answer to this question on the net so i'm posting it
> > > here.
> > > 
> > > 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.
> > [snip]
> > 
> > There is no order you can depend on. It can vary by platform, and
> >     according to optimization flags.
> 
> that was my question. which optimization flags does it depend on, and how? 
> platform is intel x86.

It is a reasonable question, but unfortunately I do not think there is
any simple answer.  Since the standard does not specify an order for
the evaluation, it is not something which the compiler, or any
compiler writer, pays attention to.  I recommend that you compile an
example using various differents sets of options, and look at the
generated assembler code to see what happens.  It may be that you
always get the same result.  It may be that you get different results
from different options.  Naturally the results you get now may change
with other versions of the compiler.

I'm sorry that I can't be more helpful.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux