I will just keep things simple:
Here is the function I built, which will create a new dnode:
struct dnode *dnode_create() {
return calloc(1, sizeof(struct dnode));
}
and here is how I call it:
struct dnode *newnode = dnode_create();
I don't understand how this involved with integer?
Either calloc
or dnode_create
doesn't have a prototype in view when you try to use it.
That means it assumes an int
return type, hence your warning message.
To ensure a prototype for calloc
is in view, include the stdlib.h
header file.
If it's the dnode_create
, you have to do it yourself, by either:
Expanding on that, both of these will work, assuming they're sequenced this way in a single translation unit (simplistically, source file). First:
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'll notice also that I've used void
in the function declaration in both cases above. There's a subtle difference between that (no parameters) and the empty parameter list (an indeterminate number of parameters). You should use the former if you really want a parameter-less function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With