This is the mail archive of the
mailing list for the GCC project.
Re: ANSI C / assignment makes pointer from integer
- To: bohdan at kivc dot vstu dot vinnica dot ua
- Subject: Re: ANSI C / assignment makes pointer from integer
- From: Sebastian Ude <ude at handshake dot de>
- Date: Tue, 07 Aug 2001 15:25:20 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <20010807152508.A10556@kivc.vstu.vinnica.ua>
- Reply-To: ude at handshake dot de
On Tue, 7 Aug 2001, firstname.lastname@example.org (Bohdan Vlasyuk) wrote:
> Date: Tue, 7 Aug 2001 15:25:08 +0300
> To: Sebastian Ude <email@example.com>
> From: firstname.lastname@example.org (Bohdan Vlasyuk)
> CC: email@example.com
> Subject: Re: ANSI C / assignment makes pointer from integer
> 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], so it's supposed
> to be declated as [remember, C remembers no type info in shared object
> files, in contrary to C++]
> int strdup(...)
> but, in given context you use it as char* = int, hence the warning.
> Usually, sizeof(int)==sizeof(char*), thus if a is char*, (char*)(int)a
> == a , but this DOES differ on many platforms other than your.
> You may deal with it by saying:
> char *strdup(const char *s);
> on the very top of your program.
I *did* include string.h.
Guess why I placed the
Yep, to tell you that I left out some lines of code which seemed natural to
Try this complete example:
char *s = strdup("foo");
string.h is included, so the definition of strdup() should be present.
But the warning is still there when compiling with -ansi ...