This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ANSI C / assignment makes pointer from integer
- To: Sebastian Ude <ude at handshake dot de>
- Subject: Re: ANSI C / assignment makes pointer from integer
- From: Bohdan Vlasyuk <bohdan at kivc dot vstu dot vinnica dot ua>
- Date: Tue, 7 Aug 2001 15:25:08 +0300
- Cc: gcc at gcc dot gnu dot org
- References: <20010807122255.420A596D37@sender.ngi.de>
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.
--
There are two ways of disliking art. One is to dislike it. The other is
to like it rationally.
-- Oscar Wilde