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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:46:45+00:00 2026-06-10T18:46:45+00:00

I’m using gcc 4.7.0, in c89 mode. I have this if-else statement and have

  • 0

I’m using gcc 4.7.0, in c89 mode.

I have this if-else statement and have 2 questions.

  1. I am just wondering should I test for the FALSE or the TRUE conditions first. What is normally better. I know it doesn’t make much difference, but I am just wondering what other engineers do? In the example below I am checking for a FALSE first.

  2. I always like to do some defensive programming. So I always if I can explicitly check each condition. for example rather than do if() – else. I would do if() – else if(). In the example below the condition can either be TRUE or FALSE. However, I always like to check the else condition to make sure that it is TRUE. Is there any real point to this?

Many thanks for any suggestions.

if(event->status == FALSE) {
    g_release_call_test(module, channel_id);
}
else if(event->status == TRUE) {
    if(UNIT_TEST & KARAOKE) {
        if(g_record_karaoke(module, channel_id) == FALSE) {
            g_release_call_test(module, channel_id);
        }
    }
    else if(UNIT_TEST & RECORD) {
        if(g_record_file_test(module, channel_id) == FALSE) {
            g_release_call_test(module, channel_id);
        }
    }
    else if(UNIT_TEST & GET_DIGITS) {
        if(g_collect_digits_test(module, channel_id) == FALSE) {
            g_release_call_test(module, channel_id);
        }
    }
}
  • 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-10T18:46:46+00:00Added an answer on June 10, 2026 at 6:46 pm

    First off, don’t do this for boolean values:

    if (something == TRUE)
    if (something == FALSE)
    

    These should rather be something like:

    if (something)
    if (!something)
    

    Boolean values should also be intelligently named so that the if statements read naturally, such as if (isFinished) or while (stillSomeMoreToGo). status is not a good name for a boolean unless it’s meant to indicate that something has a status and, even then, I’d use hasStatus or something similar.

    In any case, something can be true in C even if it isn’t equal to your TRUE value. TRUE will be, by necessity, one value whereas C defines something as true if it’s non-zero (232-1 different possible values though of course that depends on your int specification).

    Testing explicitly for true or false is a bad idea since all that does is generate another boolean, and where do you stop?

    if ((event->status == TRUE) == TRUE) ...
    if (((event->status == TRUE) == TRUE) == TRUE) ...
    if ((((event->status == TRUE) == TRUE) == TRUE) == TRUE) ...
    if (((((event->status == TRUE) == TRUE) == TRUE) == TRUE) == TRUE) ...
    

    In terms of your specific questions, for (1), it probably won’t make one bit of difference from a performance point of view. However, sometimes it can affect code readability. Choose the method that gives you the “prettiest” code, and let the compiler sort out the best way to convert your source into native form.

    The first thing I optimise for is readability, since that’s the thing that prevents most problems down the track. Once you profile the readable code and work out there’s a performance problem, then you can think about ways to improve.

    But I’ll give you this advice for free: the most impressive improvements can usually be made at the macro level (things like algorithm selection and data structure choices), rather than at the micro level (testing for true or false, counting down instead of up in loops and so on).

    For an example of readability, I tend to do short ones first (where the block inside the if is relatively concise). I also tend to do early returns first as well since they often reduce indentation. In other words, something like:

    def fn (x):
        if (x < MIN_X_ALLOWED):
            return -1
    
        # Now carry on, knowing that x >= MIN_X_ALLOWED.
    

    For (2), no, there’s no real point to this. You have explicitly decided that a boolean is needed and that only has two possible cases. You’re defending against an impossibility.

    If it were an integer, and only the values 2, 3, 5, 7 and 11 were allowed, that would be different since you’d want to defend against (for example) the value 10.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.