Ale*_*ols 3 c debugging pointers
对不起,如果这是一个过于简单的问题.我非常沮丧.
编译时,我收到以下错误:
sll.c:129: error: incompatible types in return
Run Code Online (Sandbox Code Playgroud)
这是我文件顶部的结构定义,可能需要了解发生错误的函数:
struct string_linked_list {
char *s;
struct string_linked_list *next;
};
typedef struct string_linked_list SLL;
Run Code Online (Sandbox Code Playgroud)
这是返回错误的函数.我编写的函数只是为了测试目的而构造一个单例列表.
SLL makeSingleton()
{
SLL * new= (SLL *) malloc( sizeof(SLL));
char*sp = strdup("test");
new->s = sp;
new->next = NULL;
return new;
}
Run Code Online (Sandbox Code Playgroud)
你知道问题是什么吗?
您需要指定返回类型:
SLL* makeSingleton()
{
Run Code Online (Sandbox Code Playgroud)
如果不指定,则在C中,该函数将默认返回int.
编辑:
鉴于您的新编辑,问题是您需要创建返回类型SLL*,而不是SLL:
SLL* makeSingleton()
Run Code Online (Sandbox Code Playgroud)