Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Function is deprecated

I used the code in below link:

Readline Library

And I defined a struct like this

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;

When I compile the code the compiler displays these warnings:

"Function is deprecated [-Wdeprecated-declarations]"

So what type should I change if I cannot use the function type?

like image 386
JasonChiuCC Avatar asked May 05 '17 06:05

JasonChiuCC


People also ask

What is deprecated in C?

Deprecated means the use of the name or entity declared with this attribute is allowed but discouraged for some reason. The compiler gives warnings and if string literals are provided, they are included in warnings.

Why do we get deprecated?

It is dangerous because it provides no protection against overflowing the string into which it is saving data. Programs that use gets can actually be a security problem on your computer.

When was gets deprecated?

Therefore, the function gets was removed from the C standard library in 2011. The C11 version of <stdio. h> no longer contains a declaration for gets .


1 Answers

Function is a typedef (an alias of a pointer to function returning int) marked as deprecated by the library:

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

Just use:

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;
like image 171
David Ranieri Avatar answered Sep 28 '22 16:09

David Ranieri