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, 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


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