Results 1 to 5 of 5

Thread: malloc.h error --- /usr/include/malloc.h

  1. #1
    Join Date
    May 2010
    Location
    East Bay, CA
    Posts
    32

    Default malloc.h error --- /usr/include/malloc.h

    Hello All,

    I am getting a weird compilation error with malloc.h

    /usr/include/malloc.h:86: error: expected ')' before '__size'

    This is what the code looks like inside malloc.h

    extern void *(*__morecore) __MALLOC_PMT ((ptrdiff_t __size))


    When I did some googling, it was stating that ptrdiff_t was not defined; but, it is.

    #define __malloc_ptrdiff_t ptrdiff_t


    Any ideas?


    Thanks!

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: malloc.h error --- /usr/include/malloc.h

    Post the shortest program that produces the error. Also did you include <stdlib.h> as man 3 malloc tells you to?

    BTW, Programming and Scripting is the better forum for this.

  3. #3
    Join Date
    May 2010
    Location
    East Bay, CA
    Posts
    32

    Default Re: malloc.h error --- /usr/include/malloc.h

    Hi Ken,

    Thanks for the help, and apologies for posting in the wrong spot.

    Post the shortest program that produces this error? I believe you are referring to gcc compiler here? here is the command make -f *file

    And I did include stdlib.h; but, still same errror.

    Thanks!

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: malloc.h error --- /usr/include/malloc.h

    That's not the shortest program, that's just the command you used.

    Works fine for me:

    Code:
    $ cat malloctest.c
    #include <stdlib.h>
    #include <malloc.h>
    
    int main() {
            char *buffer = malloc(100);
            printf("Hello malloc user\n");
            exit(0);
    }
    $ gcc -Wall -o malloctest malloctest.c
    malloctest.c: In function ‘main’:
    malloctest.c:5: warning: unused variable ‘buffer’
    $ ./malloctest
    Hello malloc user

  5. #5
    Join Date
    May 2010
    Location
    East Bay, CA
    Posts
    32

    Default Re: malloc.h error --- /usr/include/malloc.h

    Hi Ken,

    Thanks for the reply and tidbit code, I did verify malloc works as your code stated. But, I should have mentioned that I am using calloc.

    *ptr = calloc(1, (size_t) variable)

    But here is the strange part, I removed malloc.h include from my file and I no longer receive the error, not even an implicit declaration. Any ideas?


    Thanks!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •