5

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?

Archmede
  • 1,592
  • 2
  • 20
  • 37
JasonChiuCC
  • 111
  • 1
  • 6

2 Answers2

8

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;
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
-2

I think you should deprecate Function. And the following could work.

#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;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Yunbin Liu
  • 1,484
  • 2
  • 11
  • 20
  • Not my down-vote, but… The trouble with this suggestion is that the code uses (and needs to use) a header that includes the `typedef` for `Function`, but it is annotated as 'deprecated' (which means do not use). Your code won't work properly if the other header has been included. – Jonathan Leffler May 05 '17 at 06:53