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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:17:13+00:00 2026-05-27T03:17:13+00:00

NULL appears to be zero in my GCC test programs, but wikipedia says that

  • 0

NULL appears to be zero in my GCC test programs, but wikipedia says that NULL is only required to point to unaddressable memory.

Do any compilers make NULL non-zero? I’m curious whether if (ptr == NULL) is better practice than if (!ptr).

  • 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-27T03:17:14+00:00Added an answer on May 27, 2026 at 3:17 am

    NULL is guaranteed to be zero, perhaps casted to (void *)1.

    C99, §6.3.2.3, ¶3

    An integer constant expression with the value 0, or such an expression cast to type
    void *, is called a null pointer constant.(55) If a null pointer constant is converted to a
    pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal
    to a pointer to any object or function.

    And note 55 says:

    55) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant.

    Notice that, because of how the rules for null pointers are formulated, the value you use to assign/compare null pointers is guaranteed to be zero, but the bit pattern actually stored inside the pointer can be any other thing (but AFAIK only few very esoteric platforms exploited this fact, and this should not be a problem anyway since to “see” the underlying bit pattern you should go into UB-land anyway).


    So, as far as the standard is concerned, the two forms are equivalent (!ptr is equivalent to ptr==0 due to §6.5.3.3 ¶5, and ptr==0 is equivalent to ptr==NULL); if(!ptr) is also quite idiomatic.

    That being said, I usually write explicitly if(ptr==NULL) instead of if(!ptr) to make it extra clear that I’m checking a pointer for nullity instead of some boolean value.


    1. Notice that in C++ the void * cast cannot be present due to the stricter implicit casting rules that would make the usage of such NULL cumbersome (you would have to explicitly convert it to the compared pointer’s type every time).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Correct me if I am wrong, but it appears that the SyndicationItem.Content is null
Any ideas where the underlying word null may be coming from? This only appears
I'm trying to get a reference to cell and it appears null. If I'm
Dupe: Null Difference A lifetime ago I came across an article that explained that
ORACLE does not permit NULL values in any of the columns that comprise a
I'm sure this is something very simple that I'm screwing up, but here goes:
It appears that NHibernate cannot automap more than one IList of a given type
We're streaming a CSV file from a web service. It appears that we're losing
I have an odd bug in my program, it appears to me that malloc()
I’ve inherited a rather convoluted project. The original designer created a cookie that appears

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.