Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:42:08+00:00 2026-06-04T08:42:08+00:00

As anything non-zero means true, but the > , < , == etc. operators

  • 0

As anything non-zero means true, but the >, <, == etc. operators returning 1 for true, I’m curious if there are any notable C compilers where these operators can result in a value greater than 1.

In other words, is there any compiler where int i = (a==b); would result in undefined behavior if I intended to use i not as a boolean value, but as an integer, and was assuming it would be either 0 or 1 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:42:10+00:00Added an answer on June 4, 2026 at 8:42 am

    No, if there are, they’re not C compilers 🙂 The standard mandates that relational and equality operators return 1 for true and 0 for false.


    The rule for interpretation of integral values as boolean values by C states that 0 is false and any other value is true. See C11 sections dealing with if/while/do/for, which all contain language like "while the expression compares unequal to zero". Specifically:

    6.8.4.1/2: In both forms [of the if statement, one with and one without an else clause], the first substatement is executed if the expression compares unequal to 0. In the else form, the second substatement is executed if the expression compares equal to 0.

    6.8.5/4: An iteration statement [while, do and for] causes a statement called the loop body to be executed repeatedly until the controlling expression compares equal to 0.


    However, it’s quite explicit what result you will get for the comparison-type expressions, you either get 0 or 1. The relevant bits of the C11 standard for these are all under 6.5 Expressions:

    6.5.8/6: 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.

    6.5.9/3: The == (equal to) and != (not equal to) operators are analogous to the relational operators except for their lower precedence. Each of the operators yields 1 if the specified relation is true and 0 if it is false.

    6.5.13/3: The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0.

    6.5.14/3: The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0.

    6.5.3.3/5: The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0.


    And this behaviour goes way back to C99 and C89 (ANSI days). The C99 sections dealing with relational and equality operators also states that the return values is either 0 or 1.

    And, while the C89 draft doesn’t explicitly dictate the return values for equality operators, it does say:

    The == (equal to) and the != (not equal to) operators are analogous to the relational operators except for their lower precedence.

    And the relational operators section does state:

    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.

    Reference: http://flash-gordon.me.uk/ansi.c.txt since I don’t have any copies of the C89 standards floating around. I do have the second edition of K&R (the ANSI one from 1988) which basically says the same thing, in sections A7.9 and A7.10 of Appendix A, the Reference Manual. If you want a definitive answer from the first edition, that’ll have to come from someone with a wife less prone to throwing out old junk.


    Addendum:

    According to Michael Burr, who is either not married or has a more accommodating wife than I in terms of keeping old books 🙂

    K&R 1st Edition (1978) also says the same in 7.6 and 7.7: "The [relational operators] all yield 0 if the specified relation is false and 1 if it is true." … "The [equality operators] are exactly analogous to the relational operators except for their lower precedence."

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anything non-RESTful about providing parameters to a HTTP DELETE request? My scenario
I'm getting Reaching end of non-void function warning, but don't have anything else to
Is there a Nt or similar (i.e. non-kernelmode-driver) function equivalent for KeQueryInterruptTime or anything
Anything out there other than llvm ? libjit doesn't seem very active.. I need
Haven't seen anything about it here but it seems to solve one of the
Is there anything in Python that works like the final keyword in Java -
Is there any equivalent function on OS X to SetTimer in Windows? I'm using
There are lots of similar questions to this, but they all seem to involve
Is there anything particularly bad or naive about reading serialized data (of a known
Is there anything I can temporarily cripple Chrome with to make it mimic the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.