Field assignments are reordered in record creations

Tony Finch dot@REDACTED
Fri May 26 03:13:37 CEST 2006


On Thu, 25 May 2006, orbitz@REDACTED wrote:

> I'm not sure I follow your statements about C.  C has sequence points, they
> are && || ; , ?:

There are also sequence points before a function call and after it
returns.

> I'm not sure I understand what you mean about reading/writing bytes and
> etc have to do with ordering?

That's part of the formal model from the (discarded) annex D. The point is
that an expression may only write a location once between sequence points,
and it may not read a location after it has been written before the next
sequence point.

> And what does partial ordering mean?

If I say A<X<B and A<Y<B then I haven't said anything about the relative
order of X and Y. This is a partial order. (A total order defines the
relative order of everything.) It turns up in C expressions because there
is no requirement about the order of evaluation of X and Y in code such
as A;X+Y;B and A;f(X,Y);B. This is important when an expression has
side-effects. (Note that this is an example of when , is not a sequence
point.)

In particular:

> > Romain Lenglet wrote:
> > >
> > > 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...

C does not guarantee this, and in most cases C subexpressions can be
evaluated in any order.

Tony.
-- 
f.a.n.finch  <dot@REDACTED>  http://dotat.at/
WEST NORTHERN SECTION: IN NORTH, VARIABLE 3 OR 4 BECOMING NORTHEAST 4 OR
5, OCCASIONALLY 6 IN SOUTHEAST. MAINLY FAIR. MAINLY GOOD. IN SOUTH,
CYCLONIC 5 TO 7, OCCASIONALLY GALE 8 IN NORTHWEST. OCCASIONAL RAIN.
MODERATE OR GOOD.



More information about the erlang-questions mailing list