[c] Incompatible implicit declaration of built-in function ‘malloc’

I'm getting this error:

warning: incompatible implicit declaration of built-in function ‘malloc’

I am trying to do this:

fileinfo_list* tempList = malloc(sizeof(fileinfo_list));

Just for the reference the struct used at hand is:

typedef struct {
    fileinfo** filedata;
    size_t nFiles;
    size_t size;
    size_t fileblock;
} fileinfo_list;

I don't see anything wrong with what I've done. I'm just creating a tempList with the size of 1 x fileinfo_list.

This question is related to c struct malloc

The answer is


You're missing #include <stdlib.h>.


The only solution for such warnings is to include stdlib.h in the program.


You need to #include <stdlib.h>. Otherwise it's defined as int malloc() which is incompatible with the built-in type void *malloc(size_t).


The stdlib.h file contains the header information or prototype of the malloc, calloc, realloc and free functions.

So to avoid this warning in ANSI C, you should include the stdlib header file.


Examples related to c

conflicting types for 'outchar' Can't compile C program on a Mac after upgrade to Mojave Program to find largest and second largest number in array Prime numbers between 1 to 100 in C Programming Language In c, in bool, true == 1 and false == 0? How I can print to stderr in C? Visual Studio Code includePath "error: assignment to expression with array type error" when I assign a struct field (C) Compiling an application for use in highly radioactive environments How can you print multiple variables inside a string using printf?

Examples related to struct

How to search for an element in a golang slice "error: assignment to expression with array type error" when I assign a struct field (C) How to set default values in Go structs How to check for an empty struct? error: expected primary-expression before ')' token (C) Init array of structs in Go How to print struct variables in console? Why Choose Struct Over Class? How to return a struct from a function in C++? Initializing array of structures

Examples related to malloc

Initializing C dynamic arrays C - freeing structs malloc an array of struct pointers How do I free memory in C? How to dynamically allocate memory space for a string and get that string from user? Incompatible implicit declaration of built-in function ‘malloc’ Dynamically create an array of strings with malloc How is malloc() implemented internally? Why do I get a C malloc assertion failure? What is a Memory Heap?