相关疑难解决方法(0)

联合与无效指针

使用简单的void*而不是union的区别是什么?例:

struct my_struct {
    short datatype;
    void *data;
}

struct my_struct {
    short datatype;
    union {
        char* c;
        int* i;
        long* l;
    };
};
Run Code Online (Sandbox Code Playgroud)

这两个都可以用来完成完全相同的事情,虽然使用union或void*更好吗?

c unions

12
推荐指数
4
解决办法
5826
查看次数

标签 统计

c ×1

unions ×1