为什么这个结构体的大小是12而不是10? [英] Why is the size of this struct 12 and not 10?
本文介绍了为什么这个结构体的大小是12而不是10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析ID3v2标签,至少获取艺术家,标题和专辑等重要数据,但我无法设置必要的结构。
I'm trying to parse ID3v2 tags, at least get important data like artist, title, and album, but I'm having trouble setting up the necessary structures.
struct ID3v2_frame{
char id[4];
unsigned int size;
bool flags[2];
};
ID3v2_frame frame;
cout<<sizeof(frame)<<endl;
这是一个问题,我怎么设置一个4字节int我想。
当我输出sizeof(frame)它输出12,我的预期输出是10.
我运行在64位linux机器。
It's a problem with how I'm setting up a 4 byte int I think. When I output sizeof(frame) it outputs 12, my intended output is 10. I'm running on a 64 bit linux machine.
推荐答案
请检查您的主程序:
sizeof(bool) //should return 2 my guess
sizeof(char) //should return 1
sizeof(unsigned int) //should return 4
每个编译器对于数据类型可以有不同的大小。
Every compiler can have different sizes for data types.
这篇关于为什么这个结构体的大小是12而不是10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文