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

  • Home
  • SEARCH
  • 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 6378691
In Process

The Archive Base Latest Questions

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

This kind of struct is used as head of linked list: struct lista {

  • 0

This kind of struct is used as head of linked list:

struct lista
{
    struct lista* next;
    struct lista* prev;
};

When next and prev both points to struct itself, then the list is empty.
The following macro can be used for initializing the structure:

#define LISTA_INIT_EMPTY(list) { .next = (list), .prev = (list) }

this way:

struct lista my_list = LISTA_INIT_EMPTY(&my_list);

But, is there any way to do same thing by the following way, without macro parameter?:

struct lista my_list = LISTA_INIT_EMPTY;

I tried the following, but it caused a compile error:

#define LISTA_INIT_EMPTY     { .next = &.next, .prev = &.next }
  • 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:02:29+00:00Added an answer on May 25, 2026 at 2:02 am

    Well, the only way I see is unpleasant:

    #define LISTA_INIT_EMPTY     { .next = (&my_list), .prev = (&my_list) }
    

    Not nice at all as it only works if your variable is called my_list. And there’s no nice way as this does not exist in C.

    Why not using NULL instead of pointing to “this”? If this is not satisfactory, keeping the parameterized macro is probably the best.

    EDIT: (thanks to R’s comment below, I finally understood the need):

    As there no “this” and to only enter the name of the variable once, I suggest using such a macro:

    #define CREATE_EMPTY_LISTA(name) struct lista name = { .next=&name, .prev=&name }
    

    And later in the code:

    CREATE_EMPTY_LISTA(my_list); // creates and initializez my_list at the same time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Deque that contains this kind of stucts. struct New_Array { array<array<int,4>,4>
struct Record_node* Sequential_search(struct Record_node *List, int target) { struct Record_node *cur; cur = List->head
This kind of code would normally work in PHP, but since the scope is
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
This was the first time I encountered this kind of error after dealing with
My pages contain this kind of url: http://fashion.piliapp.com/author/http%3A%2F%2Fwww.wretch.cc%2Fblog%2Fwiwinnie/ which created by http://fashion.piliapp.com/author/ . rawurlencode(http://www.wretch.cc/blog/wiwinnie)
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
How to do this kind of events when I pressed the Preferences Button I
I have this kind of question. In my form, i got this as a
I'm getting this kind of errors while compiling any of the Win 8 Metro

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.