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 Aug  8, 2001, Bill Wendling <wendling@ncsa.uiuc.edu> wrote:

> Also sprach Sebastian Ude:
> } warning: assignment makes pointer from integer without a cast
> } 
> } The warning disappears if you would change the code like this:
> } 
> } [...]
> } 
> } char *s;
> } 
> } s = (char*) strdup("foo");
> } 
> } [...]

> If you don't have the proper header files, then "strdup" will be declared
> automagically as returning a type "int". Hence, the problem. If you
> include the proper header, this should go away.

Yep.  And if strdup is not properly declared, you'll run into problems
if you just add the cast.  There are architectures, such as
mn10300-elf, in which a different register is used for the return
value, depending on whether you're returning a pointer or something
else.  Without an appropriate declaration, strdup would return the
pointer in a0 but you'd take the garbage stored in d0 as if it were an
int and convert it to char*.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


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