This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ANSI C / assignment makes pointer from integer

On 07-Aug-2001, Bohdan Vlasyuk <> 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 <>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]