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 8413127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:51:33+00:00 2026-06-10T00:51:33+00:00

I am trying to remember if, using a standard c compiler (C89), the two

  • 0

I am trying to remember if, using a standard c compiler (C89), the two if statements below will evaluate in the same way.

snippet 1:

boolean function(formattype* format)
{
    if(format != null && (*format == format1 || *format == format2 || *format == format3) )
        return true;
    else
        return false;
}

would evaluate in the same way as snippet 2:

boolean function(formattype* format)
{

    if(format != null && (*format == format1 || format2 || format3) )
        return true;
    else
        return false;
}

I am only interested in the evaluation of the second comparison and I only added the function for illustration purposes. I seem to remember using some similar method to evaluate the == using each of the ||’d arguments without typing them all out but cannot remember the specifics.

Edit:
Perhaps the function made things more confusing than it did help illustrate.

I am trying to evaluate the following

if(format != null && (*format == format1 || *format == format2 || *format == format3) )

The first is just a check to prevent de-referencing a null pointer, so ignore it. The second three are seeing if the de-referenced format pointer is equal to any of the three different format types (they are in an enum if you must know).

I do not want to use a macro, I want to simplify the comparison. It may not be possible, I simply have a vague memory of performing a similar operation.

I thought it was something along the lines of the second example.

if(format != null && (*format == format1 || format2 || format3) )
  • 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-10T00:51:35+00:00Added an answer on June 10, 2026 at 12:51 am

    No it won’t. While the first check is valid, the second will give you an erronous result. It basically means: “If (*format equals format1) OR (format2 is nonzero) OR (format3 is nonzero)” – assuming that either of format2 or format3 is nonzero, this will always evaluate to true.

    You probably meant to tamper with bitwise operators. If format 1, 2 and 3 are different powers of two, then you can check whether *format is one of them using

    if (*format & (format1 | format2 | format3))
    

    not the bitwise (as opoosed to logical) AND and OR operators. However, this approach is not safe – it’ll evaluate to true even if the memory pointed to by format is the sum of some of the format 1, 2 and 3 constants (assuming formattype is an integral type).

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

Sidebar

Related Questions

Perhaps I'm just not using the right Google-age. But I am trying to remember
I am using Netbeans and am trying to find a way for the IDE
I am trying to implement a 'remember me' system with cookies that will remember
I'm trying to search two fields as one from a MySQL database using PHP.
I'm trying to implement a remember me feature using ASP.NET MVC. It uses a
I am trying to create a thread and from what I remember this should
I'm trying to get the rememberMe() function to remember users and retain sessions for
Short Working on login system and trying to implement remember me feature. Recently, l
I'm trying to add a remember me feature to my web app to let
I'm trying to write a registration using devise and active merchant. The form is

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.