Question about int result of relational operator

Brian Matthews blm at cxsea.UUCP
Thu Nov 3 07:19:33 AEST 1988


Randy D. Miller (randy at 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 at cxsea.UUCP   ...{mnetor,uw-beaver!ssc-vax}!cxsea!blm
+1 206 251 6811    Computer X Inc. - a division of Motorola New Enterprises



More information about the Comp.lang.c mailing list