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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:59:39+00:00 2026-05-18T19:59:39+00:00

I am currently working on rewriting a linked list module and I am receiving

  • 0

I am currently working on rewriting a linked list module and I am receiving some weird errors.

In two IDEs (Netbeans & Visual Studio Express), I am getting a warning that malloc is undefined and that a function found in my linkedlist.c file is not defined either.

below are my 3 files.

main.c

#include <stdlib.h>  
#include <stdio.h>  
#include "linkedlist.h"  
int main(void){  
 struct linked_list * l_list;   
 l_list = new_list();  
 printf("%i", l_list->length);  
 getchar();  
 return (EXIT_SUCCESS);  
}

linkedlist.h

#ifndef LINKEDLIST_H  
#define LINKEDLIST_H  
struct linked_list{  
 int length;  
 struct linked_list_node * head_node_ptr;  
};  
struct linked_list_node{  
 struct linked_list_node * prev_node_ptr;  
 struct linked_list_node * next_node_ptr;  
 struct linked_list_data * head_data_ptr;  
};  
struct linked_list_data{  
 struct linked_list_data * prev_data_ptr;  
 struct linked_list_data * next_data_ptr;  
 void * data;  
};  
struct linked_list * new_list();  
#endif  

linkedlist.c

#include "linkedlist.h"  
struct linked_list * new_list(){  
 struct linked_list * temp_list = malloc(sizeof(struct linked_list));  
 temp_list->length = 5;  
 return temp_list;  
}  

Any help would be greatly appreciated. I am unsure if this is a syntax issue or missing files on my computer.

  • 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-18T19:59:40+00:00Added an answer on May 18, 2026 at 7:59 pm

    Where do you include <stdlib.h> — because that is where malloc() is declared?

    Is this a compilation problem (malloc() undeclared) or a linking problem (malloc() undefined)?

    What exactly is the error message?


    Now the code is readable:

    • <cstdlib> is a C++ header (so is <cstdio>).
    • You need to include <stdlib.h> in C.
    • You need to include <stdlib.h> where the malloc() function is used — in linkedlist.c.

    You also have had the header guards in the wrong place in linkedlist.h, but the code in the question has been updated since. Originally, the sequence was:

    #ifndef LINKEDLIST_H  
    #define LINKEDLIST_H
    #endif
    struct linked_list{
    …
    

    The canonical structure for a header file is:

    #ifndef HEADER_H_INCLUDED
    #define HEADER_H_INCLUDED
    
    ...the other material in the header...
    ...definitions and declarations...
    
    #endif /* HEADER_H_INCLUDED */
    

    The #endif is the last non-comment, non-blank line in the file — not the third.


    Your data structures are extraordinarily complicated for even a doubly-linked list. Are you sure you’re going to be needing the length so often that it warrants maintaining the pointer to the head in every node in the list? I’d be surprised if you are using it that often. I assume that you have the pointer-to-head in each node so that when you remove an arbitrary node from the list you can decrement the length of the list. You’d probably be better off passing a pointer to the list and the pointer to the node to be deleted than what you’ve got.

    I can see no justification for the length = 5 in the new_list() function.


    Also, C and C++ differ radically on the meaning of:

    struct linked_list * new_list();
    

    In C++, that means “new_list() is a function that takes no arguments and returns a struct linked_list pointer”.

    In C, that means “new_list() is a function with a completely indeterminate argument list that returns a struct linked_list pointer”. The function is declared, but there is no prototype for the function.

    In C, you should write:

    struct linked_list * new_list(void);
    

    Personally, I prefer to see extern in front of function declarations in headers; it is not actually necessary for functions, but since it (extern) is (or should be) necessary for variables declared in headers, I prefer the symmetry for functions declared in headers.

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

Sidebar

Related Questions

No related questions found

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.