Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!mcnc!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP Newsgroups: comp.lang.c Subject: Re: short circuit evaluation Message-ID: <1971@mmintl.UUCP> Date: Tue, 3-Feb-87 18:48:36 EST Article-I.D.: mmintl.1971 Posted: Tue Feb 3 18:48:36 1987 Date-Received: Mon, 9-Feb-87 03:29:02 EST References: <425@bobkat.UUCP> <102600001@datacube> <34@umich.UUCP> <14479@amdcad.UUCP> <5199@mimsy.UUCP> <3721@teddy.UUCP> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 30 In article <3721@teddy.UUCP> jpn@teddy.UUCP (John P. Nelson) writes: >60 seconds with my copy of K&R yeilds this (Appendix A): > > "The & operator is associative and expressions involving & may be > rearranged" > > "Unlike &, && guarantees left-to-right evaluation; moreover, the second > operand is not evaluated if the first operand is zero" > >True, it is not explitly stated that & and | are not short circuited. It >also doesn't explicitly say that + and * are not short circuited! However >&& and || are EXPLICITY defined as having short circuit behavier, no other >operators are described this way, so it is safe to assume that all other >operators do NOT short-circuit. As a general rule, whatever is not specified in the C description (whether K&R or ANSI) is just that: not specified. Just because certain operators are described as having certain behavior does not guarantee that those operators for which the behavior is not specified behave in the opposite way. I would not write code which assumes that & and | are not short-circuited; nor would I write code which assumes that + and * are not short-circuited. (Although + really can't be.) But then, I use side-effects of expressions only in time-critical portions of the code, and only when the side effect is *guaranteed* to work by the language specification or in pieces of code marked as machine dependent. (However, my tendency is to write machine dependent code in assembler.) Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108