结构的大小与一个单一的元素 [英] Size of struct with a single element
本文介绍了结构的大小与一个单一的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于
struct S {
SomeType single_element_in_the_struct;
};
时总是真的
sizeof(struct S) == sizeof(SomeType)
或者,它可能是依赖于实现?
Or it may be implementation dependent?
推荐答案
这通常是这样,但它不能保证。
This will usually be the case, but it's not guaranteed.
任何结构可以在结构的末尾有不愿透露姓名的填充字节,但这些通常用于对齐的目的,这是不是一个问题,如果你只有一个元素。
Any struct may have unnamed padding bytes at the end of the struct, but these are usually used for alignment purposes, which isn't a concern if you only have a single element.
这篇关于结构的大小与一个单一的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文