Incompatible return types
Sorry if this is too simple a question. I'm just really upset.
I am getting the following error when compiling:
sll.c:129: error: incompatible types in return
Here is my structure definition at the top of my file, you might need to understand the function where the error occurs:
struct string_linked_list {
char *s;
struct string_linked_list *next;
};
typedef struct string_linked_list SLL;
Here is a function that returns an error. I wrote this function to just build a singleton list for testing purposes.
SLL makeSingleton()
{
SLL * new= (SLL *) malloc( sizeof(SLL));
char*sp = strdup("test");
new->s = sp;
new->next = NULL;
return new;
}
Do you have any idea what the problem might be?
function has an implicit return type int and you return SLL * also try to avoid naming variables "new"
You need to specify your return type:
SLL* makeSingleton()
{
If you don't specify this, in C the default function will return int.
Edit:
Given your new edit, the problem is that you need to make a return type SLL*
, not SLL
:
SLL* makeSingleton()
In your program, the return type is a pointer and therefore the program trace should be SLL* makeSingleton