P. 1
Draft ANSI C Rationale

Draft ANSI C Rationale

|Views: 5,344|Likes:
Rationale for Draft Proposed National Standard for Information Systems - Programming Language C (ANSI X3J11/88-151) (Nov 18, 1988)
Rationale for Draft Proposed National Standard for Information Systems - Programming Language C (ANSI X3J11/88-151) (Nov 18, 1988)

Availability:

See more
See less

12/17/2012

pdf

Certain syntactic forms of assignment operators have been discontinued, and others
tightened up (see §3.1.5).
The storage assignment need not take place until the next sequence point. (A
restriction in earlier drafts that the storage take place before the value of the ex-
pression is used has been removed.) As a consequence, a straightforward syntactic
test for ambiguous expressions can be stated. Some deﬁnitions: A side eﬀect is a
storage to any data object, or a read of a volatile object. An ambiguous expression is
one whose value depends upon the order in which side eﬀects are evaluated. A pure
function is one with no side eﬀects; an impure function is any other. A sequenced
expression is one whose major operator deﬁnes a sequence point: comma, &&, ||,
or conditional operator; an unsequenced expression is any other. We can then say
that an unsequenced expression is ambiguous if more than one operand invokes any
impure function, or if more than one operand contains an lvalue referencing the
same object and one or more operands specify a side-eﬀect to that object. Further,
any expression containing an ambiguous expression is ambiguous.
The optimization rules for factoring out assignments can also be stated. Let
X(i,S) be an expression which contains no impure functions or sequenced operators,
and suppose that X contains a storage S(i) to i. The storage expressions, and
related expressions, are

S(i):

Sval(i):

Snew(i):

++i

i+1

i+1

i++

i

i+1

--i

i-1

i-1

i--

i

i-1

i = y

y

y

i op= y i op y

i op y

Then X(i,S) can be replaced by either

(T = i, i = Snew(i), X(T,Sval))

or

(T = X(i,Sval), i = Snew(i), T)

provided that neither i nor y have side eﬀects themselves.

3.4. Constant Expressions

49

3.3.16.1 Simple assignment

Structure assignment has been added: its use was foreshadowed even in K&R, and
many existing implementations already support it.
The rules for type compatibility in assignment also apply to argument compati-
bility between actual argument expressions and their corresponding argument types
in a function prototype.
An implementation need not correctly perform an assignment between over-
lapping operands. Overlapping operands occur most naturally in a union, where
assigning one ﬁeld to another is often desirable to eﬀect a type conversion in place;
the assignment may well work properly in all simple cases, but it is not maximally
portable. Maximally portable code should use a temporary variable as an interme-
diate in such an assignment.

3.3.16.2 Compound assignment

The importance of requiring that the left operand lvalue be evaluated only once is
not a question of eﬃciency, although that is one compelling reason for using the
compound assignment operators. Rather, it is to assure that any side eﬀects of
evaluating the left operand are predictable.

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->