gpt4 book ai didi

c - 在自身内部定义结构对象的问题

转载 作者:行者123 更新时间:2023-12-01 16:15:49 27 4
gpt4 key购买 nike

这个有效:

struct LD__32
{
struct LD__32 *ld;
};

但这不是:

struct LD_32
{
struct LD_32 ld;
};

这是为什么?正如 pmg 猜测的那样,我正在将它编译为 C++ 代码。已编辑

最佳答案

C 中的结构不能包含类型不完整的成员。

在后一种情况下,您不能在 LD_32 定义中定义 LD_32 ld;,因为结构 LD_32 尚未定义那个点。

检查 C 中关于结构的containts

第 6.7.2.1/2 节

A structure or union shall not contain a member with incomplete or function type (hence, a structure shall not contain an instance of itself, but may contain a pointer to an instance of itself), except that the last member of a structure with more than one named member may have incomplete array type; such a structure (and any union containing, possibly recursively, a member that is such a structure) shall not be a member of a structure or an element of an array.

关于c - 在自身内部定义结构对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5329570/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com