int显示为取8个字节 [英] int shown as to take 8 bytes
本文介绍了int显示为取8个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从> https://www.geeksforgeeks.org/the-offsetof获取了代码-macro/.
我运行了gfg本身提供的ide中的代码.
I ran the code in ide provided in gfg itself.
我对代码进行了一点编辑,sizeof(int)显示4,但是通过offset占用结构中的8个字节
I have edited code a bit , sizeof(int) is showing 4 but it is shown to take 8 bytes in struct through offset
#include <stdio.h>
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
typedef struct PodTag
{
int i;
double d;
char c;
} PodType;
int main()
{
printf("%ld", OFFSETOF(PodType, d) );
getchar();
return 0;
}
推荐答案
下一个字段 d
需要8字节对齐.这意味着在字段之间插入了4个填充字节.
The next field d
requires 8 byte alignment. This means that 4 padding bytes are inserted between the fields.
在其他体系结构上可能有所不同.
On other architectures it might be different.
这篇关于int显示为取8个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文