Class Size Being Weird

So I have a class, these are all the variables:
1
2
3
4
5
6
7
8
9
10
ushort iCnt;
ui24 iBlk;
ui24 tSize[3];
ui24 bCnt;
ui24 oCnt;
bool val   : 1;
byte type  : 1;
byte table : 1;
byte shift : 1;
byte bblk  : 4;


ushort is macro for unsigned short, ui24 is a custom class of mine that is 3 bytes of data, the bit field add up to 8 bits aka 1 byte.

My calculated size = 0x15 or 21
sizeof returns 0x16 or 22

I don't get it 0.o Is there something about bit fields (I'm assuming that's the problem) I'm missing?
Last edited on
ui24 is a custom class of mine that is 3 bytes of data


I am interested in this; I once used a C++ compiler that had a "short long" type that was 3 bytes like your type. Anyway, sorry I can't help with the main problem. I just posted here because you don't accept PMs.
Last edited on
Sowwy, didn't know by default it didnt accept PM's, just changed that lol
I would've guessed this would be 0x20 bytes (32) after padding.

But just goes to show you that compilers are free to add padding as they see fit and you should never rely on a specific byte arrangement.
Topic archived. No new replies allowed.