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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:15:33+00:00 2026-05-17T18:15:33+00:00

I am writing a LinkedList in C, the below code represent my Node definition.

  • 0

I am writing a LinkedList in C, the below code represent my Node definition.

typedef struct {
    int value;
    struct Node* next;
    struct Node* prev;
} Node;

I understand (or think that I do) that struct Node not the same as typedef struct Node. Granted my code compiles and runs as it’s supposed to, however, I get a lot of warnings when assigning next and prev (warning: assignment from incompatible pointer type). I am guessing that this has to do with how I’m defining them in the Node structure.
I uploaded the full source here

So, if that is indeed the problem, how should I define next and prev inside the typedef struct Node?

I was worried this may be a repost, but couldn’t quite find what I was looking for. Thanks.

  • 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-17T18:15:33+00:00Added an answer on May 17, 2026 at 6:15 pm

    You need to do it in this order:

    typedef struct Node Node;
    
    struct Node
    {
      int value;
      Node *next;
      Node *prev;
    };
    

    That doesn’t do exactly what you asked, but it solves the problem and is how this generally is done. I don’t think there’s a better way.

    This kind of forward declaration has a second usage, in data hiding. If the list was implemented in a library, you could have just the typedef in the public header, along with functions like:

    Node * list_new(void);
    Node * list_append(Node *head, Node *new_tail);
    size_t list_length(const Node *head);
    

    This way, users of the library don’t have easy access to the internals of your library, i.e. the fields of the Node structure.

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

Sidebar

Related Questions

Writing some docs with code snippets which I want to be copyable to run
Writing an operator< () for a struct appears to be clearer than writing the
For a CS class I am writing a linked list implementation of a linked
I'm writing a function in C that takes in a linked list and a
I am writing a GTKmm window program; the main window creates two buttons, one
Writing my first JQTouch app. When I go from #login to #home , a
After writing and reading an xml string to and from a stream, it ceases
I writing a php function to check existence of bad whole words (keep in
I´m writing an application for Android in which I have a character that I
Im writing an ipad application. So far what I have is a Delegate and

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.