J
Jens.Toerring
Hi,
I have a possibly rather stupid question about the order of evaluation
in a statement like this:
result = foo( x ) - bar( y );
How can I make 100% sure that foo(x) is evaluated before bar(y), where
foo() and bar() can be either functions or macros? I got into problems
with this when writing some hardware-related stuff where foo() and bar()
are functions or macros (I want to make sure the solution is independent
of this) that read certain hardware registers and that need to be read
in a specific order. The compiler "optimized" the code by reversing the
reads, which isn't a very good idea in this case. For the time being I
found that rewritting the above as
result = foo( x );
result -= bar( y );
gets rid of the problem, but I am not sure if this really guarantees
that foo(x) is evaluated before bar(y) when I use a different compiler
or a different version. I also don't see at the moment if this can be
resolved by e.g. declaring 'result' as 'volatile', but perhaps I am
too stupid to see the obvious.
Thanks, Jens
--
_ _____ _____
| ||_ _||_ _| (e-mail address removed)-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
I have a possibly rather stupid question about the order of evaluation
in a statement like this:
result = foo( x ) - bar( y );
How can I make 100% sure that foo(x) is evaluated before bar(y), where
foo() and bar() can be either functions or macros? I got into problems
with this when writing some hardware-related stuff where foo() and bar()
are functions or macros (I want to make sure the solution is independent
of this) that read certain hardware registers and that need to be read
in a specific order. The compiler "optimized" the code by reversing the
reads, which isn't a very good idea in this case. For the time being I
found that rewritting the above as
result = foo( x );
result -= bar( y );
gets rid of the problem, but I am not sure if this really guarantees
that foo(x) is evaluated before bar(y) when I use a different compiler
or a different version. I also don't see at the moment if this can be
resolved by e.g. declaring 'result' as 'volatile', but perhaps I am
too stupid to see the obvious.
Thanks, Jens
--
_ _____ _____
| ||_ _||_ _| (e-mail address removed)-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring