经常性声明在c

1 c declaration recurring

typedef void(callback)(int*p1,sStruct*p2);

typedef struct _sStruct
{
callback *funct;
}sStruct;
Run Code Online (Sandbox Code Playgroud)

我在C中有以下声明.如何在不收到任何错误的情况下编译此循环声明?

目前我收到:第一行'*'标记之前的语法错误.

Tyl*_*nry 11

您可以转发声明结构:

/* Tell the compiler that there will be a struct called _sStruct */
struct _sStruct;

/* Use the full name "struct _sStruct" instead of the typedef'ed name
   "sStruct", since the typedef hasn't occurred yet */
typedef void (callback)(int *p1, struct _sStruct *p2);

/* Now actually define and typedef the structure */
typedef struct _sStruct
{
  callback *funct;
} sStruct;
Run Code Online (Sandbox Code Playgroud)

编辑:已更新以匹配问题的类型名称更改.

另外,我强烈建议您不要给结构标识符_sStruct.以a开头的全局名称_是保留名称,将它们用于您自己的标识符可能会导致未定义的行为.