This is the mail archive of the
mailing list for the GCC project.
Re: ANSI C / assignment makes pointer from integer
On 07-Aug-2001, Bohdan Vlasyuk <email@example.com> wrote:
> On Tue, Aug 07, 2001 at 02:25:15PM +0200, Sebastian Ude wrote:
> > Assume this (very common) situation:
> > Looks pretty harmless, doesn't it ?
> > But both gcc 2.95.3 and egcs 1.1.2 give me the following warning
> > when compiling this code with -ansi:
> > warning: assignment makes pointer from integer without a cast
> > But why ?
> You, obviously, hadn't declared your function, and hadn't included
> header file declaring it [<string.h> on my system]
Actually it's a bit more complicated than that.
strdup() is a non-standard function, so as well as #including <string.h>,
you also need to compile with the right options; if you compile with
`ansi', then strdup() will not be declared even if you #include <string.h>.
If you want to write standard-conforming code, don't use strdup().
The simplest solution is to write a version of strdup() yourself,
name it something different, e.g. `sebastian_strdup()', and use that.
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.