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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:12:35+00:00 2026-05-25T02:12:35+00:00

instead of checking every input pointer argument with if condition if( in != NULL

  • 0

instead of checking every input pointer argument with if condition if( in != NULL ), is there better way to do this. One method is to create some macros, like

#define CHECK_ARG(x) if(!(x)) { return 0; }

In code it’s look like this

int some_func( int * first_arg, int * second_arg )
{
    CHECK_ARG( first_arg );
    CHECK_ARG( second_arg );

    // some operations
    //
}

In my opinion this is good approach, but before adding this, I want to know is there any better ways doing this?

Thanks in advance!

  • 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-25T02:12:36+00:00Added an answer on May 25, 2026 at 2:12 am

    In your function write

    assert_or_return(first_arg != NULL);
    assert_or_return(second_arg != NULL);
    

    Define assert_or_return so that in the debug version it will fire up the debugger (by calling abort), and in the release version it will log the error and return (as you want to do). I assume you’re confident that returning from the function when one of the arguments is NULL will do more good than harm in the production version of your application. If by returning early you will irrevocably corrupt your users’ data or cause a furnace to explode, it would be better to terminate early, perhaps with a custom error message.

    The following example illustrates how your idea can be implemented.

    #ifdef NDEBUG
    #define assert_or_return(expr) do { \
      if (!(expr)) { \
        fprintf(logfile, "Assertion %s in %s(%d) failed\n", #expr, __FILE__, __LINE__); \
        return 0; \
      } \
    } while(0)
    #else
    #define assert_or_return(expr) do { \
      if (!(expr)) { \
        fprintf(stderr, "Assertion %s in %s(%d) failed\n", #expr, __FILE__, __LINE__); \
        abort(); \
      } \
    } while(0)
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of using $this->fetchAll('email = ?',$email)->current() inside the model class, is there a way
Instead of returning a common string, is there a way to return classic objects?
instead of checking all my post variables from a form one at a time
Is there a tool replacing javadoc with something that is more Wiki-style syntax instead
Possible Duplicates: Fastest way to list all primes below N in python Checking if
I'm trying to optimize some code and I want to instead on checking a
I'm refactoring a medium-sized WinForms application written by other developers and almost every method
I found this directory checking code on the web and modified it a little,
...instead of using the Atom syndication format? Atom is a well-defined , general-purpose XML
Instead of writing my ASP.NET C# applications in Visual Studio, I used my favorite

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.