Field assignments are reordered in record creations
Thu May 25 06:24:56 CEST 2006
Romain Lenglet wrote:
> David, thanks a lot fot this great explanation.
> I expected the Erlang compiler to behave like a C compiler, and
> to execute subexpressions with possible side-effects in the same
> order as they are written...
I think you might have misunderstood my explanation. In *both* C
and Erlang, the order of evaluation of procedure arguments is
unspecified (because the spec for each language explicitly says so).
In Erlang, that's the whole story. All you need to know is that ','
specifies left-to-right evaluation, and other operators don't.
No concept of sequence points is needed or useful.
In C, it's a whole lot more complicated. In fact I'm pretty sure
that most C programmers don't understand how much more complicated.
There is a partial ordering of "events", where an event is one of:
- reading the value of a byte,
- writing a value to a byte,
- designation of a byte in an object,
- a function call,
- a sequence point
and each subexpression constrains the ordering. Then there are rules
about which sets of possible orderings cause undefined and/or unspecified
behaviour, which are sufficiently vague that comp.std.c can have several-
month-long flamewars about how they should be interpreted.
So, it's probably not a good idea to try to understand other languages'
evaluation orders in terms of concepts from C. Most other languages are
David Hopwood <david.nospam.hopwood@REDACTED>
More information about the erlang-questions