以下联盟表示什么?

时间:2012-09-12 01:55:06

标签: c unions

struct  ifreq {
    char    ifr_name[IFNAMSIZ];             
    union {
            caddr_t ifr_d;
    } ifr;
};

这里他们使用了union,我没有明白为什么他们在那里只使用了一个元素时使用了? 只有在需要使用2-3个元素时才能使用union。

由于

1 个答案:

答案 0 :(得分:3)

很多可能性。但是,在这种情况下,它看起来像是因为定义是从相应的Linux标题中删除的,它们只是采用了他们需要的部分。 struct ifreq看起来像这样,通常是:

struct ifreq {
    char ifr_name[IFNAMSIZ]; /* Interface name */
    union {
        ...
    };
};
相关问题