Path: utzoo!utgpu!attcan!uunet!husc6!mailrus!cornell!uw-beaver!fluke!ssc-vax!cxsea!blm From: blm@cxsea.UUCP (Brian Matthews) Newsgroups: comp.lang.c Subject: Re: Question about int result of relational operator Message-ID: <2554@cxsea.UUCP> Date: 2 Nov 88 21:19:33 GMT References: <787@gtx.com> Reply-To: blm@cxsea.UUCP (Brian Matthews) Distribution: na Organization: Computer X Inc. Lines: 29 Randy D. Miller (randy@gtx.UUCP) writes: |I've seen conflicting information about the int result of a relational |operator in which the condition is satisfied. Does it evaluate to |exactly one, or just "non-zero" ? E.g., can we test whether two |comparisons have the same relational result with the following ? | int a,b,c,d; | if ((a > b) == (c > d)) { | /* both tests have the same relational result */ | } From Section 3.3.8 "Equality operators" of the ANSI draft standard, last paragraph under Semantics: "Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false. The result has type int." From Section 3.3.9 "Equality operators", first paragraph under Semantics: "The == (equal to) and the != (not equal to) operators are analogous to the relational operators except for their lower precedence." It is also guaranteed in K&R, but I don't have a K&R handy, so I can' give you a section or page number. -- Brian L. Matthews blm@cxsea.UUCP ...{mnetor,uw-beaver!ssc-vax}!cxsea!blm +1 206 251 6811 Computer X Inc. - a division of Motorola New Enterprises