SGE
SGE

Reputation: 2367

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.

Upvotes: 181

Views: 231528

Answers (5)

cnicutar
cnicutar

Reputation: 182764

You likely forgot to #include <stdlib.h>

Upvotes: 404

santosh sahu
santosh sahu

Reputation: 51

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.

Upvotes: 5

Omri Barel
Omri Barel

Reputation: 9490

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).

Upvotes: 48

user3828152
user3828152

Reputation: 17

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

Upvotes: -4

Antti
Antti

Reputation: 12489

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

Upvotes: 16

Related Questions