From: Ian Lance Taylor <iant@google.com>
To: Robert Dell <dellr@mac.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: warning: incompatible implicit declaration of built-in function 'malloc'
Date: Thu, 27 Jan 2011 06:35:00 -0000 [thread overview]
Message-ID: <mcry666svkw.fsf@google.com> (raw)
In-Reply-To: <4D410614.8010107@mac.com> (Robert Dell's message of "Thu, 27 Jan 2011 00:43:48 -0500")
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
next prev parent reply other threads:[~2011-01-27 6:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 5:43 Robert Dell
2011-01-27 6:35 ` Ian Lance Taylor [this message]
2011-01-27 13:18 ` Robert Dell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mcry666svkw.fsf@google.com \
--to=iant@google.com \
--cc=dellr@mac.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).