C 中的循环定义
我写的是:
typedef enum _MyStatus
{
MY_STATUS_OK = 0,
MY_STATUS_GENERAL_ERROR = -1,
} MyStatus;
typedef MyStatus (*MyCallback)(MySettings *settings);
typedef struct _MySettings
{
MyCallback callback;
} MySettings
但是,它不会编译,因为在定义 MyCallback 时它不知道 MySettings。如果我交换 MySettings 和 MyCallback,情况就会相反:MySettings 不会知道 MyCallback。
C 语言通常如何处理此类问题?
谢谢!
What I've written is:
typedef enum _MyStatus
{
MY_STATUS_OK = 0,
MY_STATUS_GENERAL_ERROR = -1,
} MyStatus;
typedef MyStatus (*MyCallback)(MySettings *settings);
typedef struct _MySettings
{
MyCallback callback;
} MySettings
However, it wouldn't compile as when defining MyCallback it doesn't know of MySettings. If I swapped MySettings and MyCallback, it would be the other way round: MySettings wouldn't know of MyCallback.
How generally is this sort of problem handled in C?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何将这一行放在顶部:
此 C 常见问题解答:如何定义一对相互引用的结构? 可能有用。
How about putting this line at the top:
This C FAQ: How can I define a pair of mutually referential structures? might be of use.