C 函数已弃用
C Function is deprecated
我使用了下面的代码 link:
然后我定义了一个这样的结构
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;
当我编译代码时,编译器显示这些警告:
"Function is deprecated [-Wdeprecated-declarations]"
那么如果不能使用函数类型,应该换什么类型呢?
Function
是一个 typedef
(指向函数返回 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;
我认为您应该弃用 Function。以下可能有效。
#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;
}
我使用了下面的代码 link:
然后我定义了一个这样的结构
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;
当我编译代码时,编译器显示这些警告:
"Function is deprecated [-Wdeprecated-declarations]"
那么如果不能使用函数类型,应该换什么类型呢?
Function
是一个 typedef
(指向函数返回 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;
我认为您应该弃用 Function。以下可能有效。
#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;
}