This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: warning: incompatible implicit declaration of built-in function 'malloc'
- From: Ian Lance Taylor <iant at google dot com>
- To: Robert Dell <dellr at mac dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 26 Jan 2011 22:35:11 -0800
- Subject: Re: warning: incompatible implicit declaration of built-in function 'malloc'
- References: <4D410614.8010107@mac.com>
Robert Dell <dellr@mac.com> writes:
> can somebody please explain why I'm getting this warning?
> warning: incompatible implicit declaration of built-in function 'malloc'
>
> char *returnval = 0;
> long outputBytes = 0;
> ... outputBytes gets changed and tested to ensure it's valid (non zero) ...
>
> the offending line is here.
> returnval = (char *) malloc(outputBytes + 2);
You are calling the malloc function, but you have not declared it. That
means it gets the type "extern int malloc();". Since you are compiling
in hosted mode (the default), gcc knows that that declaration is
incorrect, and it is warning about that (the correct declaration is
"extern void *malloc(size_t);").
Typically this is fixed by adding
#include <stdlib.h>
to the start of your file.
Ian