Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: problem in type conversion Message-ID: <431@bbncca.ARPA> Date: Tue, 3-Jan-84 10:44:07 EST Article-I.D.: bbncca.431 Posted: Tue Jan 3 10:44:07 1984 Date-Received: Wed, 4-Jan-84 03:06:03 EST References: <1603@randvax.ARPA> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 32 ------------------------------- 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