Either calloc
or dnode_create
does not have a prototype when you try to use it.
This means that it assumes an int
return type, hence your warning message.
To ensure that the prototype for calloc
is in view, include the stdlib.h
header file.
If it is dnode_create
, you must do it yourself, either:
- defining a function before using it (in this source file); or
- Declaring a prototype before using it.
Expanding, both of them will work, assuming that they are ordered in this way in one translation unit (simplified, in the source file). First of all:
struct dnode *dnode_create (void) { // declare & define return calloc(1, sizeof(struct dnode)); } : { // inside some function struct dnode *newnode = dnode_create(); // use }
Or:
struct dnode *dnode_create (void); // declare : { // inside some function struct dnode *newnode = dnode_create(); // use } : struct dnode *dnode_create (void) { // define return calloc(1, sizeof(struct dnode)); }
You will also notice that I used void
in the function declaration in both cases above. There is a subtle difference between them (without parameters) and an empty list of parameters (an indefinite number of parameters). You should use the first if you really need a function without parameters.
source share