结构的类型为规模贡献 [英] Struct's contribution to type size

查看:141
本文介绍了结构的类型为规模贡献的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很奇怪,为什么以下两种类型

I am wondering why the following two types

struct {
    double re[2];
};

double re[2];

在C中的大小相同?不增加结构尺寸开销一点?

have the same size in C? Doesn't struct add a bit of size overhead?

推荐答案

没有,它只是仅仅构成所有的元素融入其中更高级别的元素,它的大小仅仅是个别元素的尺寸增加了(加上一些填充取决于对齐方式规则,但是这出这个问题的范围)。

No, it just merely composes all the elements into one higher-level element whose size is merely the individual elements' sizes added up (plus some padding depending on alignment rules, but that's out of the scope of this question).

这篇关于结构的类型为规模贡献的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆