编译器报错类型冲突
Compiler complains of conflicting types
我试图建立一个链表,但在编译我的代码时,我得到以下错误:
In file included from linkedlist.c:1:
linkedlist.h:9: warning: 'struct list_t' declared inside parameter list
linkedlist.h:9: warning: its scope is only this definition or declaration, which is probably not what you want
linkedlist.h:12: warning: 'struct list_t' declared inside parameter list
linkedlist.c: In function 'main':
linkedlist.c:11: warning: passing argument 2 of 'execute_choice' from incompatible pointer type
linkedlist.c: At top level:
linkedlist.c:28: error: conflicting types for 'execute_choice'
linkedlist.h:9: error: previous declaration of 'execute_choice' was here
linkedlist.c:56: error: conflicting types for 'create_node_in_linked_list'
linkedlist.h:12: error: previous declaration of 'create_node_in_linked_list' was here
linkedlist.h:9: warning: 'struct list_t' declared inside parameter list
linkedlist.h:9: warning: its scope is only this definition or declaration, which is probably not what you want
linkedlist.h:12: warning: 'struct list_t' declared inside parameter list
make: *** [all] Error 1
然而,我检查了源文件和头文件,'execute_choice'函数在两者中都有匹配的声明。以下是我的源文件和头文件:
源文件:#include "linkedlist.h"
int main (void)
{
int choice;
list_t* list;
list = (list_t*)sizeof(list_t);
while (1) {
choice = display_menu_choices();
execute_choice(choice, list);
}
}
int display_menu_choices(void)
{
int menu_choice;
printf ("Please select from the following optionsn");
printf ("0. Exit programn");
printf ("1. Generate a linkedlistn");
printf ("2. Sort a linkedlistn");
scanf ("%d", &menu_choice);
return menu_choice;
}
void execute_choice(int menu_choice, list_t* list)
{
switch (menu_choice) {
case GEN_LL:
generate_linked_list();
break;
case SORT_LL:
sort_linked_list();
break;
case EXIT:
exit(0);
}
return;
}
void generate_linked_list(void)
{
return;
}
void sort_linked_list(void)
{
return;
}
void create_node_in_linked_list(list_t* list)
{
return;
}
头:#include <stdlib.h>
#include <stdio.h>
#define EXIT 0
#define GEN_LL 1
#define SORT_LL 2
int display_menu_choices(void);
void execute_choice(int, struct list_t*);
void generate_linked_list(void);
void sort_linked_list(void);
void create_node_in_linked_list(struct list_t*);
typedef struct node_t{
struct node_t* current;
struct node_t* next;
int value;
} node_t;
typedef struct list_t{
struct node_t* start;
} list_t;
此外,一般的提示是受欢迎的!请批评我的代码,但你觉得有必要-我永远不会从我的错误中吸取教训,如果没有人指出他们=)谢谢!!
你必须在使用它之前声明它的类型。
因此,如果您将结构定义/类型定义移动到函数原型之前,编译器应该停止抱怨隐式/冲突的定义。
头文件中的内容顺序是错误的。typedef
应该出现在函数定义之前。移动
typedef struct node_t{
struct node_t* current;
struct node_t* next;
int value;
} node_t;
typedef struct list_t{
struct node_t* start;
} list_t;
之前int display_menu_choices(void);
void execute_choice(int, struct list_t*);
相关文章:
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- C++哈希表 - 如何解决自定义数据类型作为键的unordered_map冲突?
- 模板冲突的类型-但类型应该是相同的cfr类层次结构
- 冲突声明/重新定义:不同的基本类型
- 可变参数的冲突类型
- 致命错误LNK1112:在 npm 安装期间,模块计算机类型'X86'与目标计算机类型'x64'冲突
- GCC 6.3.0 中的 ODR 冲突,类型在两个单独的翻译单元中定义
- 通过参考推断模板包中的冲突类型
- 错误:在 mingw64 上构建 cmake+boost 项目时'GetSystemTimeAsFileTime'的类型冲突
- 致命错误LNK1112:通过 vcvarsall .bat x86 运行构建'X86'模块计算机类型'x64'与目标计算机类型冲突
- 冲突的声明类型/价值不匹配
- 如何解决"sprintf"的冲突类型?
- 忽略候选模板:推断参数的冲突类型:<常量 T &> 与 <T &>
- 错误:调用"反向"没有匹配函数:候选模板被忽略:推断出参数的冲突类型
- 为虚拟析构函数指定的冲突类型属性
- C++ 模板错误,并推断参数的冲突类型
- 推导参数'T'的冲突类型以供通用参考
- C++错误:推断出参数'T'字符串与常量字符的冲突类型 *
- 函数和冲突类型的隐式声明- AVR
- 'memchr'的冲突类型