Thread: Queue operations giving undefined reference to malloc

  1. #16
    Registered User
    Join Date
    Nov 2018
    Posts
    13
    Thanks for the hack! I ran this on my computer and as you said it is giving the desired output.
    And Yes, I agree that array will be overwritten, that's what I thought first and then I thought, something else and convinced.

    For this kind, what will be the suggestion to fix? I tried with struct (I am not much into this, but have reference code) as posted in post #1, I am getting malloc undefined reference. SO I cannot use malloc and free()

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,616
    > 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?
    Perhaps if you gave us some useful links to online documentation about your target, we could advise.

    But malloc/free are prototyped in stdlib.h, which you don't include.
    Then again, you're running on a micro controller where very few rules apply.

    I guess from the create() and resume() calls that you have some rudimentary OS available.

    > kprintf("\n \n ---- Message recived: %s ----\n", mssg2);
    In Linux, kprintf() operates in kernel space, not user space.

    Just a guess, but is the malloc you should be using called kmalloc?

    If there truly is no dynamic memory, then at a pinch you could try
    Code:
    char msgs[10][100];
    and use strcpy() to both copy messages into the queue, and copy messages out of the queue.
    Your receiver will need to supply a buffer for this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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