Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.misc Subject: Re: Many people's opinions on computer languages (was: Third public review of X3J11 C) Message-ID: <429@quintus.UUCP> Date: 19 Sep 88 07:08:53 GMT References: <8365@smoke.ARPA> <225800053@uxe.cso.uiuc.edu> <8374@smoke.ARPA> <340@quintus.UUCP> <910@l.cc.purdue.edu> <8695@ihlpb.ATT.COM> <1386@garth.UUCP> <585@aiva.ed.ac.uk> <1433@garth.UUCP> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 28 In article <1433@garth.UUCP> smryan@garth.UUCP (Steven Ryan) writes: >If short-circuit && and || were not defined, then p && q and p || q >could be equivalent to p & q and p | q, with programmer responsible for >dangerous side-effects. In Ada this would perturb the code, >but it is not a problem in C or Algol because of the existence of conditional >expression. I am puzzled by the reference to ADA, which has and {roughly "&"} and then {same as "&&"} or {roughly "|"} or else {same as "||"} and is thus the same as C (apart from having a separate boolean type). Why I say "roughly" is that if p and q are completely free of side effects, it is still not the case that "p&&q" and "p&q" have the same value. Consider, for example, p==4, q==2. Then p&&q is defined to be 1, but p&q is 0. For the same numbers, p||q is also 1, but p|q is 6. If you want an expression with the same value as p&&q, you have to write !!(p) & !!(q) There are three separate things: (a) bitwise masking operations (b) "pure" logical operations (c) short-circuit operations Fortran and Pascal conflate (b) and (c), leaving it up to the compiler to decide which to use. C omits (b), providing only (a) and (c). Algol 60 provides (b) and if-expressions. Algol 68 provides (a), (b), and if- expressions. I think most people will agree that C is an improvement over BCPL, where the same symbol was used for both & and &&, but if you used it in a "value" context you got "&", while in a "control" context you got "&&".