Circular definition in C

我的未来我决定 提交于 2019-12-02 08:44:39

问题


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!


回答1:


How about putting this line at the top:

typedef struct _MySettings MySettings;

This C FAQ: How can I define a pair of mutually referential structures? might be of use.



来源:https://stackoverflow.com/questions/7502730/circular-definition-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!