20090103

malloc in stdlib.h

nick wrote:[color=blue]
>
> the following is my programming code and compile message
> why the warning message arise, have i done somethings wrong?
>
> #include<stdio.h>[/color]

You neglected to write this here:

#include <stdlib.h>
[color=blue]
> d = (card*) malloc(sizeof(card));[/color]
[color=blue]
> test.c:11: warning: implicit declaration of function `malloc'[/color]

The declaration for malloc, is in stdlib.h.
Without the declaration in scope,
C89 assumes malloc returns type int.

With the declaration in scope,
the compiler knows that malloc returns type pointer to void.
The (card*) cast that you used, suppressed the warning
that you would have gotten for assigning an int value
to a pointer type.

Add
#include <stdlib.h>
and lose the cast.

--
pete

http://bytes.com/groups/c/223337-what-meaning-implicit-declaration-function-malloc