可能重复:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?C结构的大小
我有这样定义的简单C结构:
typedef struct LMWinData {
UInt8 itemTypeID;
UInt16 serviceID;
UInt16 methodID;
} LMWinData;
在代码后来我定义一个变量像这样的这种类型:
LMWinData lmWinData;
现在,如果我打印出这个变量的大小:
NSLog(@"data has size of %lu bytes", sizeof(lmWinData));
我没有得到预期值(5个字节)。我得到的是6字节的大小。
那么,这里有什么问题?
非常感谢!
(我正在使用Mac OS X Lion。)
非常感谢!我使用了'编译包(1)'方法,解决了这个问题。 –