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: ?: grouping Message-ID: <469@bbncca.ARPA> Date: Thu, 12-Jan-84 10:18:48 EST Article-I.D.: bbncca.469 Posted: Thu Jan 12 10:18:48 1984 Date-Received: Fri, 13-Jan-84 06:10:51 EST References: <2481@azure.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 31 ----------------------------- Steve Summit asks, >>>> How should ?: group? The C Reference Manual says it groups left >>>> to right, just like all the binary operators. In the case of a >>>> ternary operator it's not as obvious what "left to right" means, >>>> but I would think that a?b:c?d:e should be evaluated as >>>> (a?b:c)?d:e (do the leftmost one first). I agree that this is the correct interpretation of "left to right" in this case. However, what we have here is a genuine bug in the C Reference Manual, which says in section 7.13 (page 191 of K&R), "Conditional expressions group right-to-left," and in section 18.1 (page 215 of K&R), "Binary operators and the conditional operator all group left-to-right. . ." I believe that the right-to-left grouping is correct because section 18 (page 214, K&R) says, "This summary of C syntax is intended more for aiding comprehension than as an exact statement of the language." This seems to indicate that section 7.13 takes precedence. FLASH!! I just took a look at the UN*X System V "Programming Guide" published by Western Electric, and the error has been fixed. In that manual, the syntax summary agrees that the conditional operator groups right-to-left. Personally, I feel that if practical compilers should issue a "Warning: cryptic code" message when encountering unparenthesized expressions like the above. -- Morris M. Keesan {decvax,linus,wjh12}!bbncca!keesan keesan @ BBN-UNIX.ARPA