problem in type conversion

Morris Keesan keesan at bbncca.ARPA
Wed Jan 4 01:44:07 AEST 1984


-------------------------------
    The problem with ( E1 op= E2 ) generating a different result than
( E1 = E1 op (E2) ) may or may not be a compiler problem.  The root of the
problem seems, as usual, to be in the language definition.  Section 7.14
of the C Reference Manual (p. 191 of K&R) gives a list of all the assignment
operators, and then says (capitals mine):

	In the simple assignment with =, the value of the expression
    replaces that of the object referred to by the lvalue.  If both      
    operands have arithmetic type, the right operand is converted to
    the type of the left preparatory to the assignment.
	The behavior of an expression of the form E1 op= E2 MAY BE
    INFERRED BY TAKING IT AS equivalent to E1 = E1 op (E2); . . .

It is unclear here whether the second sentence, referring to type conversions,
applies only to the simple assignment with =, or to all the assignment
operators.  It is equally unclear whether the next sentence is an exact
definition of what the op= operators do, or a definition by example and
hand-waving.  Simply reading the manual would seem to indicate that the
conversion of the right operand to the type of the left should only occur for
the simple case, but the behavior of the compilers would seem to indicate a
different intent.
    What is clear is that there is a serious problem here, as you say, and that
the language definition should be revised in the direction of clarity.  I'm not
sure whether this should mean changing the language to behave in the
intuitively correct fashion, or changing the manual to reflect the actual
behavior of the existing compilers.  It's the old problem of improvement vs.
compatibility.
-- 
					Morris M. Keesan
					{decvax,linus,wjh12}!bbncca!keesan
					keesan @ BBN-UNIX.ARPA



More information about the Comp.lang.c mailing list