Thread: Queue operations giving undefined reference to malloc

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    13

    Question Queue operations giving undefined reference to malloc

    Hello,

    I am trying to implement a message storage (string type) and retrieval functionality, where I have 3 c files:

    main.c
    sender.c --> this will have send function
    receiver.c --> this will have receive function

    main.c needs to call the sender.c send to store the message and
    main.c needs to call the receiver.c receive to get the message in FIFO.

    So far to do this, I have created a new msgs.h file, sender.c and receiver.c
    But with this, I am getting compilation errors as my micro controller don't have malloc library. Is there any alternative and workable solution to do this?


    Code:
    //msgs.h
    #define MAXMESSGS 10
     
    struct node
    {
        char* data[10]; //--> I guess this is also not correct
        struct node *link;
    }*front, *rear;

    Code:
    //sender.c
    #include <msgs.h>
    send() {
    
      // SOME OTHER STUFF
    
    
        struct node *temp;
     
        temp = (struct node*)malloc(sizeof(struct node));
        temp->data = msg;
        temp->link = NULL;
        if (rear  ==  NULL)
        {
            front = rear = temp;
        }
        else
        {
            rear->link = temp;
            rear = temp;
        } 
    }
    Code:
    //receiver.c
    #include <msgs.h>
      receive ()
    {
    
      // SOME OTHER STUFF
    
       struct node *temp;
        temp = front;
         if (front == NULL)
        {
          printf("queue is empty \n");
         front = rear = NULL;
        }
        else
        {    
          msg=front->data;
          front = front->link;
          free(temp);
        }
    return msg;
    }
    Errors:
    Code:
    sender.c: undefined reference to malloc
    receiver.c: undefined reference to free
    Last edited by karumudi7; 11-28-2018 at 07:13 PM. Reason: updated msgs.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Program to implement queue operations using linear queue
    By riteshkrjain in forum C Programming
    Replies: 2
    Last Post: 10-03-2017, 10:57 AM
  2. compiler keeps giving undefined reference errors
    By ecsx00 in forum C Programming
    Replies: 1
    Last Post: 11-24-2011, 03:12 AM

Tags for this Thread