Clang returns an incompatible integer to pointer conversion returning 'int' from a function with result type 'struct node *'
error when my create_node function checks whether the ptr malloc returns is NULL:
struct node *create_node(void)
{
// mallocs memory for new node
node *new_node = malloc(sizeof(node));
// check to make sure not out of memory, quits if is
if (new_node == NULL)
{
return 1;
}
// sets bool checking if word is in dictionary to false
new_node->is_word = false;
// set all ptrs in struct node 'branch' to NULL because don't point to anything yet
for (int i = 0; i < 27; i++)
{
new_node->branch[i] = NULL;
}
return new_node;
}
I get it's point: the function I wrote returns a struct node and if (new_node == NULL) is true, it returns an int, but the only fix I've found is to eliminate those lines. Is it appropriate to do so and if it is, can you explain why it's ok in this context? My understanding is it's a good practice to check if the ptr malloc returns is NULL in case you're out of memory and had been doing so before I managed to create this error.
Feel free to point out anything else which is wrong and thanks in advance for the help.