Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!cmcl2!brl-adm!adm!dsill@NSWC-OAS.arpa From: dsill@NSWC-OAS.arpa (Dave Sill) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <8212@brl-adm.ARPA> Date: Wed, 8-Jul-87 11:37:41 EDT Article-I.D.: brl-adm.8212 Posted: Wed Jul 8 11:37:41 1987 Date-Received: Sat, 11-Jul-87 06:34:28 EDT Sender: news@brl-adm.ARPA Lines: 37 Ross Alexander (auvax!rwa) has been blasted for saying: >Isn't there a little room here for arguement [over the value of an >assignment expression]? But if one reads his next sentence: >Now of course K&R say >that an expression is coerced to the type it is being assigned to. one can see that he was not disputing "the correct behavior" of C compilers implementing K&R, but was asking us to question whether this is consistent with the philosophy of the language. Given this context, his point: >So the coercion for the assignment of `int' to `char' in >this case is a side effect and shouldn't have an affect on the value >of the whole expression `( c = getchar() )'. makes a lot of sense. Another example may help clarify the point. Consider long i, func(); short j; i = j = func(...); Under K&R, the return value of func will be converted to short before the assignment to j takes place. If, however, this value is too large to fit in a short it will be truncated. The value assigned to i, then, will be the one assigned to j. Ross's point, I believe, was that this is probably more likely to cause trouble than if the value of an assignment expression was defined to be the right-hand side. I wouldn't suggest changing the semantics of C in this case, but it's something to keep in mind. -Dave Sill dsill@nswc-oas.arpa The opinions expressed above are those of the author and do not reflect the opinions or policy of the Department of Defense or the U.S. Navy.