c - 我可以使用常量结构进行循环引用吗?

标签 c struct circular-reference

我可以在 C99 中这样做吗? ?

typedef struct dlNode {
    dlNode* next, prev;
    void* datum;
} dlNode;

const static dlNode head={
    .next = &tail,
    .prev = NULL,
    .datum = NULL
};

const static dlNode tail={
    .next = NULL,
    .prev = &head,
    .datum = NULL
};

没有这个我也可以让我的程序运行。这会很方便。

最佳答案

可以。您只需转发声明 tail 即可使其正常工作:

typedef struct dlNode {
    struct dlNode* next;
    struct dlNode* prev;
    void* datum;
} dlNode;

const static dlNode tail;

const static dlNode head={
    .next = &tail,
    .prev = NULL,
    .datum = NULL
};

const static dlNode tail={
    .next = NULL,
    .prev = &head,
    .datum = NULL
};

关于c - 我可以使用常量结构进行循环引用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46289498/

相关文章:

C unix,套接字上的非对称加密

c++ - 为什么这个结构的大小不正确

c++ - 从结构/类读取/写入文件

python - 删除字典、列表、元组中的循环引用

c - 为什么 main 没有声明为 extern

c - 在c中的套接字上发送一个空终止字符

go - 在go中导入struct,得到 "not a type"错误

.net - EF 4.1 + MVC + JSON 循环引用异常的最佳解决方案?

dependency-injection - 使用 StructureMap 时是否有方法检测和调试循环引用?

c - 在c中使用char数组实现一个64 block 逻辑磁盘