关于C中的结构松弛字节 [英] slack byte in structures in C
本文介绍了关于C中的结构松弛字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是什么意思松弛字节结构C.请帮助。
what is mean by slack byte in structures in C. please help.
推荐答案
通常填充字节,以确保数据正确对齐。例如:
Usually padding bytes to ensure that data is aligned correctly. For example:
struct x {
int a; // four bytes
char b; // one byte
// three bytes slack
int c; // four bytes
} xx;
将可能有间松弛字节b
和 C
获得 C $ C $ç对准正确的边界上>。
您可以看到检查这是什么 sizeif(XX)
为您提供了(12的情况下,虽然上面这依赖于实现)。
You can check this by seeing what sizeif(xx)
gives you (12 in the case above although it depends on the implementation).
一些体系运行速度减慢,如果他们不得不使用(例如)是不是一个4字节边界上对齐一个4字节的值。的部分的结构不会允许,在所有的,而不是产生异常。
Some architectures run slower if they have to use (for example) a four byte value that isn't aligned on a four-byte boundary. Some architectures won't allow that at all, instead generating an exception.
这篇关于关于C中的结构松弛字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文