I saw such union inside struct definition in pure c code in Linux kernel sources struct cma_multicast
(it's not the only one place. Seems that it is some common practice):
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;
};
But I can't figure out what is the purpose of union with only one member inside the struct? Why can't we just type struct ib_sa_multicast *ib;
?
I read this post but it has no usage explanation and has C++ specificity only.
UPD:
Posted example from Linux kernel instead of proprietary code.