home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!Germany.EU.net!ira.uka.de!smurf.sub.org!ppcnet!ppcger!Sepp
- Message-ID: <qBak-G@ppcger.ppc.sub.org>
- From: Sepp@ppcger.ppc.sub.org (Josef Wolf)
- Newsgroups: comp.lang.c
- Subject: Re: Order of evaluation?
- Distribution: world
- Organization: PPC Germersheim, Germany
- Date: 8 Nov 92 16:39:01 GMT
- References: <3736@dozo.and.nl> <1992Oct27.002204.11825@den.mmc.com> <josef.720691377@uranium> <1992Nov2.192805.17329@CSD-NewsHost.Stanford.EDU> <1dau8nINNk59@uranium.sto.pdb.sni.de> <1992Nov6.125409.23455@unipalm.co.uk>
- Lines: 57
-
- In <1992Nov6.125409.23455@unipalm.co.uk> tim@unipalm.co.uk (Tim Goodwin) writes:
- ] Josef Moellers <mollers.pad@sni.de> writes:
- [ ... ]
- ] > a() * b() * c() * e() * f() * g()
- [ ... ]
- ] In the quoted example, each of the functions must be evaluated (although
- ] there is no guarantee about the order in which they are evaluated). It
- ] is possible that the compiler might avoid some of the multiplications,
- ] if it happens to notice that they are unnecessary, but it may not omit
- ] any of the function calls.
-
- Well, let's please go back to the original thread. Say: is the compiler
- allowed to evaluate the expression given above in the following order:
-
- a() * (b() * c()) * e() * f() * g() ?
-
- Let's take a look at Section A7.6:
-
- A7.6 Multiplicative operators
-
- The multiplicative operators *, /, and % group left to right.
- [ ... ]
-
- So the world seems to be OK. But look at Section A7:
-
- A7 Expressions
-
- [ ... ]
- The precedence and associativity of operands is fully specified, but
- the order of evaluation of expressions is, with certain exceptions,
- ^^^^^^^^^^^^^^^^^^^
- undefined, even if the subexpressions involve side effects. That is,
- unless the definition of an operator guarantees that its operands are
- evaluated in a particular order, the implementation is free to evaluate
- operands in any order, or even to interleave their evaluation. [ ... ]
- This rule revokes the previous freedom to reorder expressions with
- operators that are mathematically commutative and associative, but
- can fail to be computationally associative. [ ... ]
-
- So the compiler seems to be allowed to evaluate
-
- a * ( b * c ) instead of a * b * c
-
- but not
-
- a * ( b / c ) instead of a * b / c
-
- Is this correct?
-
- Greetings
- Sepp
-
- --
- | Josef Wolf, Germersheim, Germany aka sepp@ppcger.ppc.sub.org |
- | also available via ..!uunet.uu.net!ira.uka.de!smurf!ppcger!sepp |
- |--------------------------------------------------------------------------|
- | ...und wieviel brave Deutsche haben wieder nichts geschnallt... (Marius) |
-