This is the mail archive of the gcc@gcc.gnu.org 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 Tue, 7 Aug 2001, bohdan@kivc.vstu.vinnica.ua (Bohdan Vlasyuk) wrote:
> Date: Tue, 7 Aug 2001 15:25:08 +0300
> To: Sebastian Ude <ude@handshake.de>
> From: bohdan@kivc.vstu.vinnica.ua (Bohdan Vlasyuk)
> CC: gcc@gcc.gnu.org
> 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

[...]'s

Yep, to tell you that I left out some lines of code which seemed natural to
me.

Try this complete example:

#include <string.h>

int main(void)
  {
     char *s = strdup("foo");
     return 0;
  }

string.h is included, so the definition of strdup() should be present.
But the warning is still there when compiling with -ansi ...


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