I am converting some Objective-C++ code into plain Objective-C and I am having some trouble with structs. For both languages, I have the struct declared in the .h file like this.
struct BasicNIDSHeader {
short messageCode;
short messageDate;
int messageTime;
int messageLength;
short sourceID;
short destID;
short numberOfBlocks;
};
In C++, the struct is being declared like
BasicNIDSHeader header;
and in Objective-C I do this
struct BasicNIDSHeader header;
The code for using them is actually the same in both languages.
memset(&header, 0, sizeof(header));
[[fileHandle readDataOfLength:sizeof(header)] getBytes:&header];
where fileHandle is a NSFileHandle.
The problem is than in the original C++ code, sizeof(header) = 18. When using Objective-C, sizeof(header) = 20.
Any ideas why this is happening or how to fix it? The code is dependent on the size being like it is in C++. I can just hardcode it, but would like to have a better understanding of why it is happening. Plus I hate hardcoding constants.
Thanks!