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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:39:53+00:00 2026-06-10T07:39:53+00:00

Is there any benefit of casting NULL to a struct pointer in C ?

  • 0

Is there any benefit of casting NULL to a struct pointer in C ?

For example:

typedef struct List
{
....
} List;

List *listPtr = ((List *) NULL) ;

Example from PostgreSQL source:

#define NIL                     ((List *) NULL)

http://doxygen.postgresql.org/pg__list_8h_source.html

  • 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-10T07:39:55+00:00Added an answer on June 10, 2026 at 7:39 am

    In assignment example the explicit cast make no useful sense. However, it seems that you the question is really about #define NIL ((List *) NULL) macro, whose usability extends beyond assignment.

    One place where it might make sense is when you pass it to a variadic function or to a function declared without a prototype. The standard NULL can be defined as0 or 0L or ((void *) 0) or in some other way, meaning that it might be interpreted differently in such type-less contexts. An explicit cast will make sure that it is interpreted correctly as a pointer.

    For example, this is generally invalid (behavior is undefined)

    void foo();
    
    int main() {
      foo(NULL);
    }
    
    void foo(List *p) {
      /* whatever */
    }
    

    while replacing the call with

    foo(NIL);
    

    makes it valid.

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

Sidebar

Related Questions

Is there any benefit in having never-defined structures in C ? Example in SQLite
I'm wondering why List<T>.ForEach(Action<T>) exists. Is there any benefit/difference in doing : elements.ForEach(delegate(Element element){
A part from memory usage, is there any benefit using an Int32 on a
From what Ive seen. emacs etc.. run in terminal. Is there any benefit to
Is there any benefit to include the length specifier in a format string for
I there any benefit to putting the javascript references in individual pages vs the
Is there any benefit (or conversely, cost) to passing a parameter by const value
When using Google app engine is there any benefit to use a CDN if
Possible Duplicate: C# member variable initialization; best practice? Is there any benefit to this:
Is there any performance benefit/technical differences between calling EF SaveChanges() in a foreach loop

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.