C Programming: malloc() inside another function

后端 未结 9 1095
暖寄归人
暖寄归人 2020-11-22 06:47

I need help with malloc() inside another function.

I\'m passing a pointer and size to the fu

9条回答
  •  情深已故
    2020-11-22 07:06

    This does not make sense :

    if(alloc_pixels(input_image, bmp_image_size)==NULL) 
    

    alloc_pixels returns a signed char (ERROR or NO_ERROR) and you compare it to NULL (which is supposed to be used for pointers).

    If you want input_image to be changed, you need to pass a pointer to it to alloc_pixels. alloc_pixels signature would be the following:

    signed char alloc_pixels(unsigned char **ptr, unsigned int size)
    

    You would call it like this:

    alloc_pixels(&input_image, bmp_image_size);
    

    And the memory allocation

    *ptr = malloc(size);
    

提交回复
热议问题