C 注:先前的隐含声明‘;点向前’;在这里
我似乎无法正确编译这个递归函数,我也不知道为什么。 代码如下:C 注:先前的隐含声明‘;点向前’;在这里,c,C,我似乎无法正确编译这个递归函数,我也不知道为什么。 代码如下: void point_forward (mem_ptr m) { mem_ptr temp; temp = m->next; if (temp->next != NULL) point_forward(temp); m->next = temp->next; } 我的编译器返回以下内容: mm.c:134:6:警告:“点向前”的类型冲突[默认启用] mm.c:96:2:注:之前隐含的“前进点
void point_forward (mem_ptr m) {
mem_ptr temp;
temp = m->next;
if (temp->next != NULL) point_forward(temp);
m->next = temp->next;
}
我的编译器返回以下内容:
mm.c:134:6:警告:“点向前”的类型冲突[默认启用]mm.c:96:2:注:之前隐含的“前进点”声明在此 关键在于: “前进点”之前的隐含声明就在这里 在第96行,您有:
point_forward(m); // where m is a mem_ptr;
由于编译器尚未看到点向前(m)
的函数声明,因此它“隐式定义”(即假设)了一个返回int的函数:
int point_forward(mem_ptr m);
这与后面的定义相冲突:
void point_forward (mem_ptr m) {
要解决此问题,您可以:
void point_forward(mem_ptr m)代码>这将告诉编译器在第96行看到它时如何处理point_forward()
,即使它还没有看到函数实现
- 如果不想在任何其他C文件中使用
,请完整定义它:point\u forward()
在源文件的顶部static void point_forward(mem_ptr m){..函数体在这里..}
- 如果要在其他C文件中使用
,请提出一个前进声明:point\u forward()
在头文件中包含其他文件void point_forward(mem_ptr m);