开发者

Getting Unexpected result with 'sizeof(union.variable)'->Objective C

I am getting unexpected result for the below code.

开发者_高级运维union
{
    int aBuf[RMH_MAX_UNENCODED_LENGTH+sizeof(MSG_INFO)]; //4070+68=4138
}sUnion;
NSLog(@"%d",sizeof(sUnion.aBuf));//printing as 16552 and not 4138


That is the correct output for this code. Your union contains an array of 4138 int types. If you ran NSLog(@"%d",sizeof(int));, the output would be 4. 4*4138=16552, so an array of 4138 ints is 16552 bytes long.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜