【发布时间】:2020-11-23 12:31:55
【问题描述】:
我在Linux内核源代码struct cma_multicast中的纯c代码中看到了这样的结构定义内部联合(这不是唯一的一个地方。似乎这是一些常见的做法):
struct cma_multicast {
struct rdma_id_private *id_priv;
union {
struct ib_sa_multicast *ib;
} multicast;
struct list_head list;
void *context;
struct sockaddr_storage addr;
struct kref mcref;
};
但我无法弄清楚结构内只有一个成员的联合的目的是什么?为什么我们不能直接输入struct ib_sa_multicast *ib; ?
我读过这个post,但它没有使用说明,只有 C++ 特性。
UPD:
从 Linux 内核而不是专有代码发布示例。
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: c c data-structures struct linux-kernel union