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: Bill Wendling <wendling at ncsa dot uiuc dot edu>
- Subject: Re: ANSI C / assignment makes pointer from integer
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 10 Aug 2001 20:31:11 -0300
- Cc: Sebastian Ude <ude at handshake dot de>, gcc at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
- References: <20010807122255.420A596D37@sender.ngi.de><20010808161320.B17512@ncsa.uiuc.edu>
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