- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我似乎无法让这个递归函数正确编译,我也不知道为什么。代码如下:
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: warning: conflicting types for ‘point_forward’ [enabled by default]
mm.c:96:2: note: previous implicit declaration of ‘point_forward’ was here
最佳答案
关键在于:
previous implicit declaration of ‘point_forward’ was here
在第 96 行,您有:
point_forward(m); // where m is a mem_ptr;
由于编译器尚未看到 point_forward(m)
的函数声明,因此它“隐式定义”(即假设)一个返回 int 的函数:
int point_forward(mem_ptr m);
这与后面的定义冲突:
void point_forward (mem_ptr m) {
<小时/>
要解决此问题,您可以:
在第 96 行之前放置一个显式声明:void point_forward(mem_ptr m);
这将告诉编译器在看到point_forward()
时如何处理它位于第 96 行,即使它还没有看到函数实现。
或者,在第 96 行上方定义整个函数(将函数定义从第 134 行向前移动到第 96 行上方)。
这里有一点more about declaring functions .
一般来说,为了风格,我会:
如果您不想在任何其他 C 文件中使用 point_forward()
,请完整定义它:
static void point_forward(mem_ptr m) { ..函数体放在这里.. }
位于源文件的顶部。
如果要在其他 C 文件中使用 point_forward()
,请添加前向声明:
void point_forward(mem_ptr m);
在头文件中供其他文件包含。
关于c - 注意: previous implicit declaration of ‘point_forward’ was here,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267361/
我似乎无法让这个递归函数正确编译,我也不知道为什么。代码如下: void point_forward (mem_ptr m) { mem_ptr temp; temp = m->next;
我似乎无法让这个递归函数正确编译,我也不确定为什么。代码如下: void point_forward (mem_ptr m) { mem_ptr temp; temp = m->next;
我是一名优秀的程序员,十分优秀!