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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:33+00:00 2026-06-12T19:09:33+00:00

I am attempting to construct my first linked list, and having read a basic

  • 0

I am attempting to construct my first linked list, and having read a basic introduction, have done the following. Firstly, declare a linked list node as:

struct errorNode {
    uint8 error;
    struct errorNode* next;
};

Secondly, define the first node globally as:

struct errorNode errorList = {0, NULL};

This has been done to allow each of the libraries that make up my current project to insert errors into a common list. The function to do this is:

void errorListWrite(uint8 error) {
    struct errorNode* newNode = malloc(sizeof(struct errorNode));

    newNode->error = error;

    newNode->next = &errorList;
    errorList = *newNode;
}

Whilst this compiles without error, it does not function as expected. I thnk the problem is with the last two statements of the list write function, but I am unsure. A hint as to what I am doing wrong would be most appreciated.

  • 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-12T19:09:34+00:00Added an answer on June 12, 2026 at 7:09 pm

    The problem is that you create a circular list.

    newNode->next = &errorList;
    

    So newNode links to the global node.

    errorList = *newNode;
    

    This is equivalent to errorList.error = newNode->error; errorList.next = newNode->next;.
    So now errorList links to the global node. Oops.

    What you could do instead, is insert the new node after the global node in the list:

    newNode->next = errorList.next;
    errorList.next = newNode;
    

    This is assuming that you want a global node at all. If you don’t, then you could start with struct errorNode *errorList = 0;, and add a new node like this:

    newNode->next = errorList;
    errorList = newNode;
    

    When you come to use the list, your list-traversal may look a little different. With a global pointer-to-node you’ll start with a pointer to the first node, that you must check for null before using. With a global node you’d start with a node that definitely exists, but whose next pointer might be null.

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

Sidebar

Related Questions

I'm attempting to learn OOP and have a few questions. I've read the first
I'm attempting to implement a stack using a linked list. My stack constructor createStack()
I'm attempting to construct rich-text where the first part says Looking for: and is
I'm attempting to use Doctrine ORM for the first time, and I'm following the
I am attempting to construct my own date picker using code from several sources.
I am attempting to construct my own date picker using code from several sources.
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Attempting/struggling to get registration and sign-up working within an active admin project. I have
I am attempting to construct a component tree in JSF 1.2 (Mojarra) where the

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.