3

I believe what I am looking for is referred to as forecasting...

I want to typedef a Function Pointer that refers to a struct, and then that Function pointer is stored in the struct. See ShellCmdDEF below.

typedef BOOL (*ShellCmdFN) (struct ShellCmdDEF* pCmd, uint16_t u16State);

typedef struct
{
    uint32_t    u32Flags;
    uint16_t    u16State;
    ShellCmdFN  pCmdFN;

} ShellCmdDEF;

The compiler complains thusly...

Shell.h:57:71: warning: 'struct ShellCmdDEF' declared inside parameter list [enabled by default] Shell.h:57:71: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]

Of course the code works, and I have done this for years, but now it's for Misra/DO170B compliance and I need to get rid of the warnings.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Syntactics
  • 313
  • 4
  • 8

1 Answers1

10

Declare the structure before the function pointer type:

struct ShellCmd;

typedef BOOL (*ShellCmdFN) (struct ShellCmd* pCmd, uint16_t u16State);

typedef struct ShellCmd
{
    uint32_t    u32Flags;
    uint16_t    u16State;
    ShellCmdFN  pCmdFN;
} ShellCmdDEF;
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621