注:“point_forward'previous隐式声明在这里 [英] note: previous implicit declaration of ‘point_forward’ was here

查看:226
本文介绍了注:“point_forward'previous隐式声明在这里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到这个递归函数来正确编译,我不知道为什么。
在code是如下:

 无效point_forward(mem_ptr米){
  mem_ptr温度;
  TEMP = M->接下来,
  如果(TEMP-GT&;!下次= NULL)point_forward(TEMP);
  M->接下来= TEMP->接下来,
}

我的编译器返回这样的:


  

mm.c:134:6:警告:冲突的类型'point_forward[默认启用]

  mm.c:96:2:注意:previous的point_forward'隐式声明在这里



解决方案

关键是这个:


  

previous的隐式声明的'point_forward在这里


在96行有:

  point_forward(米); //其中m是一个mem_ptr;

由于编译器目前还没有看到对 point_forward(M),其隐式定义(即假定)返回一个int函数的函数声明:

  INT point_forward(mem_ptr米);

这与后来的定义冲突:

 无效point_forward(mem_ptr米){


要解决这个问题,您可以:


  1. 把一个明确的报关行96在什么地方:无效point_forward(mem_ptr米); 这将告诉编译器如何对待 point_forward ()当它看到它在线96,尽管目前还没有看到该功能的实现。


  2. 或者,上述定义96行整体功能(从线路134函数定义移动起以上线路96)。


下面是一点点更多有关声明功能的。

一般情况下,对于风格,我要么:


  • 如果你不想使用 point_forward()在任何其他C文件,完全定义它:

    静态无效point_forward(mem_ptr米){..function的身体去这里..}

    在源文件的顶部。


  • 如果你想使用 point_forward()在其他C文件,把推进声明:

     无效point_forward(mem_ptr米);

    在头文件中的其他文件,包括


I can't seem to get this recursive function to compile properly, and I'm not sure why. The code is as follows:

void point_forward (mem_ptr m) {
  mem_ptr temp;
  temp = m->next;
  if (temp->next != NULL) point_forward(temp);
  m->next = temp->next;
}

My compiler returns this:

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

解决方案

The key is in this:

previous implicit declaration of ‘point_forward’ was here

On line 96 you have:

point_forward(m); // where m is a mem_ptr;

Since the compiler hasn't yet seen a function declaration for point_forward(m), it "implicitly defines" (ie, assumes) a function that returns an int:

int point_forward(mem_ptr m);

This conflicts with the definition later:

void point_forward (mem_ptr m) {


To fix this, you can either:

  1. Put an explicit declaration somewhere before line 96: void point_forward(mem_ptr m); This will tell the compiler how to treat point_forward() when it sees it on line 96, even though it hasn't yet seen the function implementation.

  2. Or, define the whole function above line 96 (move the function definition from line 134 onwards to above line 96).

Here is a little bit more about declaring functions.

Generally, for style, I would either:

  • If you don't want to use point_forward() in any other C files, define it in full:

    static void point_forward(mem_ptr m) { ..function body goes here.. }

    at the top of the source file.

  • If you want to use point_forward() in other C files, put a forward declaration:

    void point_forward(mem_ptr m);
    

    in a header file for other files to include.

这篇关于注:“point_forward'previous隐式声明在这里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆