malloc returns int?

Michael Meissner meissner@cygnus.com
Tue Jul 25 12:14:00 GMT 2000


On Tue, Jul 25, 2000 at 02:51:20PM -0400, gif wrote:
> using gcc v 2.95.2 on a freeBSD box,
> this program:
> 
> main()
> {
>   void *bar = malloc(10);
> }
> 
> returns this warning when compiled:
> point.c: In function `main':
> point.c:3: warning: initialization makes pointer from integer without a cast
> 
> malloc should be returning void *, not int, yes?   

Malloc does return void *.  You just need to include <stdlib.h> to properly
define it (C treats all calls to functions that haven't been defined yet as
returning int).  This would be apparent on some 64-bit systems (because int is
only 32-bits on those systems) or on some 68k systems (where ints are returned
in d0 and pointers are returned in a0).

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482


More information about the Gcc-bugs mailing list