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 int
s is 16552 bytes long.
精彩评论