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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:49:47+00:00 2026-06-18T00:49:47+00:00

When I call a function that expects a pointer, and I pass in a

  • 0

When I call a function that expects a pointer, and I pass in a value, I get this warning, and I like that.

But when the value happens to be a literal ‘0’, I don’t get the warning. I think this is because C think it’s null-pointer, and not a value. Is there any way to still get warnings for 0-literals, because I already had some bugs because of it.

  • 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-18T00:49:48+00:00Added an answer on June 18, 2026 at 12:49 am

    GCC supports a nonnull attribute on function parameters that can do what you want (as long as the -Wnonnull warning option is enabled):

    void* foo( int* cannot_be_null)  __attribute((nonnull (1))) ;
    
    
    int main(int argc, char *argv[])
    {
        int x;
        foo(&x);
    
        foo(0);  // line 13 - generates a -Wnonnull warning
    
        return 0;
    }
    

    When compiled using gcc -c -Wnonnull test.c I get:

    test.c: In function 'main':
    test.c:13:5: warning: null argument where non-null required (argument 1) [-Wnonnull]
    

    You can force this to be an error with -Werror=nonnull.

    Note that this warning is only thrown when the null pointer literal (another name for 0) is used – the following code doesn’t trigger the warning:

    int* p = NULL;
    foo(p);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that call a function with undefined arguments, like this: #include
Can you call a Javascript function that expects let's say five arguments, and supply
Can you call a function that has no body but is declared in the
I'm trying to call a function that contains jQuery code. I want this function
I would like to have a function that can wrap any other function call.
I've been experimenting with function types in C++. Note that I don't mean pointer-to-function
Please suppose I have a function that accepts a pointer as a parameter. This
How do you wrap a C function call that expects a pre-allocated char** as
I'm using a Python API that expects me to pass it a function. However,
I want to call a function that may throw an exception. If it does

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.