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

  • SEARCH
  • Home
  • 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 6103697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:45:29+00:00 2026-05-23T13:45:29+00:00

Suppose we have 3 variables and we need to ASSERT that they can either

  • 0

Suppose we have 3 variables and we need to ASSERT that they can either all be equal to -1 or neither can be equal to -1. I wrote the following code:

x := 1;
y := 1;
z := 1;

ASSERT( (x = -1) = (y = -1) = (z = -1) );

I often write this kind of check, but for two variables. Surprisingly the triple comparison compiled too, but it doesn’t work as expected. For (1, 1, 1) values I expect it to evaluate to true. After substitution of variable values and simplification we get:

ASSERT( False = False = False );

and I thought that it should evaluate to True, but it doesn’t. So how is this triple comparison evaluated?

  • 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-05-23T13:45:30+00:00Added an answer on May 23, 2026 at 1:45 pm

    First of all, the = operator is a binary operator: it always works on a pair of values. So there’s no such thing as a “triple equality”. The compiler will evaluate one pair, and use the result to evaluate the other.

    When the compiler sees multiple linked operators, it needs to group them into pairs using what’s called the “precedence of operators”. It’s clear if you think about the basic arithmetic operators we learned in primary school. There’s no doubt what: 3+2*4 evaluates to: it’s equivalent to 3+(2*4). When in doubt, always add the grouping yourself. If you do that, you see your expression is equivalent to:

    ((False = False) = False), and it’s obvious it evaluates to:

    (True = False).

    What you probably want is to use the AND operator and group your initial Assert like this:

    ASSERT(((x = -1) = (y = -1)) and ((y = -1) = (z = -1)))

    Then I’d probably either write that expression on multiple lines to make the AND operator obvious (SQL habit, I know), or rewrite it completely:

    Assert (
      ((x = -1) = (y = -1))
      and
      ((x = -1) = (z = -1))
    );
    

    or this variant:

    Assert (
      ((x = -1) and (y = -1) and (z = -1))
      or
      ((x <> -1) and (y <> -1) and (z <> -1))
    );
    

    My rule is: if it takes more then 1 second to figure out the precedence of operators, add parentheses.

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

Sidebar

Related Questions

Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a variable of type Int = 08, how can I convert
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have the following CSS rule in my page: body { font-family: Calibri,
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I want to know about timer in Python. Suppose i have a code snippet
Suppose I have the following struct: struct sampleData { int x; int y; };
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int
Okay, suppose I have a bunch of variables, one of them declared volatile: int

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.