public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* warning: incompatible implicit declaration of built-in function 'malloc'
@ 2011-01-27  5:43 Robert Dell
  2011-01-27  6:35 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Dell @ 2011-01-27  5:43 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: warning: incompatible implicit declaration of built-in function 'malloc'
  2011-01-27  5:43 warning: incompatible implicit declaration of built-in function 'malloc' Robert Dell
@ 2011-01-27  6:35 ` Ian Lance Taylor
  2011-01-27 13:18   ` Robert Dell
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2011-01-27  6:35 UTC (permalink / raw)
  To: Robert Dell; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: warning: incompatible implicit declaration of built-in function 'malloc'
  2011-01-27  6:35 ` Ian Lance Taylor
@ 2011-01-27 13:18   ` Robert Dell
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Dell @ 2011-01-27 13:18 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Ian Lance Taylor wrote:
> 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
>
>   
see? i thought it would be something simple, that fixed it.  thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-27 13:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-27  5:43 warning: incompatible implicit declaration of built-in function 'malloc' Robert Dell
2011-01-27  6:35 ` Ian Lance Taylor
2011-01-27 13:18   ` Robert Dell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).