2017-05-05 109 views
4

我使用的代码在下面的链接:C功能已被弃用

Readline Library

我定义如下

typedef struct { 
    char *name;   /* User printable name of the function. */ 
    Function *func;  /* Function to call to do the job. */ 
    char *doc;   /* Documentation for this function. */ 
} COMMAND; 

一个struct当我编译编译器显示这些警告的代码:

“功能已过时[-Wdeprecated-declarations]”

那么,如果我不能使用函数类型,应该更改哪种类型?

+0

您介意创建[___MCVE___](http://stackoverflow.com/help/mcve)吗? –

+0

你得到的*确切的错误*是什么? –

+0

看看警告消息,它也会告诉你哪个函数已被弃用 –

回答

6

Functiontypedef(一个指针的别名函数返回int)标记为弃用的library

typedef int Function() __attribute__ ((deprecated)); 

只需使用:

typedef struct { 
    char *name;   /* User printable name of the function. */ 
    int (*func)();   /* Function to call to do the job. */ 
    char *doc;    /* Documentation for this function. */ 
} COMMAND; 
-3

我想你应该弃用功能。以下内容可以工作。

#include <stdio.h> 

typedef void (*Function)(); 

typedef struct { 
    char *name;   /* User printable name of the function. */ 
    Function *func;  /* Function to call to do the job. */ 
    char *doc;   /* Documentation for this function. */ 
}COMMAND; 

int main() { 
    COMMAND commond; 

    puts("end"); 



    return 0; 
} 
+0

不是我的倒票,但是......这个建议的麻烦是代码使用(并且需要使用)包含'typedef'的头文件'Function',但它被注释为'弃用'(这意味着不使用)。如果包含其他头文件,您的代码将无法正常工作。 –

+0

对不起。我是一个新的编码器。我正在学习英语。 –