Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!princeton!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <7056@alice.UUCP> Date: Sat, 4-Jul-87 11:11:02 EDT Article-I.D.: alice.7056 Posted: Sat Jul 4 11:11:02 1987 Date-Received: Sat, 4-Jul-87 20:25:59 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <262@auvax.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 40 In article <262@auvax.UUCP>, rwa@auvax.UUCP writes: > what is the value of x in this fragment: > > float x; > int i; > > x = 2.0 + ( i = 3.5 ); > > I would say 5.5; others might say 5.0, it seems. But if I _wanted_ > 5.0, I would expect to write > > x = 2.0 + (int) ( i = 3.5 ); > > and I appeal to the principle of least astonishment for justification. Ah yes, what should be the value of an assignment? The LHS or the RHS? Both answers have their pitfalls, and C says the correct answer is (a copy of) the LHS. Thus the answer in your example is 5.0. While this produces a surprise in your particular case, consider: double d, a, sqrt(); d = 2; a = sqrt(d); a = sqrt(d=2); Now, don't you want the second and third assignment above to do the same thing? In APL, the value of an assignment is the value of its right-hand side. This mostly works well, but leads to some surprises too: A <- 0 0 0 0 0 B <- A[2 3 4] <- 6 B <- A[2 3 4] The first line sets A to a five-element array, all of whose elements are zero. The second line sets A[2], A[3], and A[4] to 6, and also sets B to 6. The third line sets B to a three- element array whose elements are all 6.