learning C (was: Re: ambiguous ?)

Richard O'Keefe ok at cs.mu.oz.au
Thu Oct 26 16:06:41 AEST 1989


In article <14124 at lanl.gov>, jlg at lanl.gov (Jim Giles) writes:
: From article <2523 at munnari.oz.au>, by ok at cs.mu.oz.au (Richard O'Keefe):
: > Well, that depends.  To start with, temporary variables have the great
: > merit of being a familiar means.  That's how you force argument
: > evaluation order in Algol 60, Pascal, Ada, Fortran (66, 77, 8X), Modula,
: > Lisp, Simula 67, ... 
: 
: Most of those languages also have _other_ means of forcing evaluation
: order in useful contexts.  For example, all of the above mentioned 
: languages allow the user to prohibit optimization of expressions
: involving associative operators - using parentheses.  The C argument
: that parentheses should be used _only_ for legibility always seemed
: rather silly 

Working backwards:
 - last time I heard about the ANSI draft it *did* require that
   parentheses be respected a la Fortran
 - I've never heard of any "C argument that parentheses should be used
   only for legibility".  On the contrary, the C argument was that
   parentheses had to be used so heavily in macros to protect against
   context that it was better they should have only syntactic force
 - Lisp is one of "the above mentioned languages" and it most certainly
   does NOT allow the user to prohibit expression optimisation using
   parentheses (parentheses make lists!)
 - there seems to be a confusion between association and order of
   elaboration.  In reading this thread, whenever Giles has written about
   "argument evaluation order" I had assumed that he was talking about
   things like
	in f(x) + g(x), is f() called then g(), or g() called then f()?
   What made me think this was the discussion of the order of evaluation
   of arguments to functions.
   Parentheses in Algol, Fortran, Pascal, Ada, and the rest have NO
   relevance to that question.  What parentheses force is association:
	(A + B) + C
   must be calculated as
	add A, B giving temp
	add temp, C giving result
   However, the values of A, B, and C may be calculated in any order.
   This is relevant when it comes to function calls.  Consider
	( P(X) .AND. Q(X) ) .AND. R(X)
   in Fortran.  It is legal for a Fortran compiler to generate code
   equivalent to
	t1 = q(x);
	t2 = r(x);
	t3 = p(x);
	result = (t3 & t1) & t2
   The parentheses control the order in which the values of the leaves of
   the expression tree are combined, but not the order in which the values
   of those leaves are obtained.



More information about the Comp.lang.c mailing list