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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:19:15+00:00 2026-05-14T14:19:15+00:00

I generally have ignored using macros while writing in C but I think I

  • 0

I generally have ignored using macros while writing in C but I think I know fundamentals about them. While I was reading the source code of list in linux kernel, I saw something like that:

#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
    struct list_head name = LIST_HEAD_INIT(name)

(You can access the remaining part of the code from here.)

I didn’t understand the function of ampersands(I don’t think they are the address of operands here) in LIST_HEAD_INIT and so the use of LIST_HEAD_INIT in the code. I’d appreciate if someone can enlighten me.

  • 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-14T14:19:15+00:00Added an answer on May 14, 2026 at 2:19 pm

    To know what actually is happening we need the definition of struct list_head:

    struct list_head {
            struct list_head *next, *prev;
    };
    

    Now consider the macros:

    #define LIST_HEAD_INIT(name) { &(name), &(name) }
    #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
    

    If in the code I write LIST_HEAD(foo) it gets expanded to:

    struct list_head foo = { &(foo) , &(foo)}
    

    which represents an empty doubly linked list with a header node where the next and prev pointers point to the header node itself.

    It is same as doing:

    struct list_head foo;
    foo.next = &foo;
    foo.prev = &foo;
    

    So effectively these macros provide a way to initialize a doubly linked list.

    And yes, & is used here as the address of operator.

    EDIT:

    Here is a working example

    In the link provided by you. You had:

    struct list_head test = LIST_HEAD (check);
    

    which is incorrect. You should have:

    LIST_HEAD (check);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a logging module that can have reporting enabled/disabled at runtime. Calls generally
(This question specifically in C#, but applies generally to .NET) I have a largish
I normally work on single threaded applications and have generally never really bothered with
I have found that there is generally a singe type or namespace that takes
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
I have the feeling that Flash -based ( or Silverlight -based) websites are generally
Generally the database server is the biggest, most expensive box we have to buy
I have a general exception handler, Application_error in my global.asax where I'm trying to
The general problem: We have urls coming to our IIS web servers formatted like:
I have to give a general note to some huge Java project for which

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.