• Welcome to Jose's Read Only Forum 2023.
 

UDTs are padded out to the size of their largest primitive member

Started by Chris Chancellor, February 06, 2019, 03:50:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello Charles

in the link at O2 forum

https://www.oxygenbasic.org/forum/index.php?topic=1858.msg20109;topicseen#msg20109

you mentioned that in 64bits
QuoteUDTs are padded out to the size of their largest primitive member

does this means that the padding is automatically done by the O2 compiler?   

and there is no need for us to add in the padding manually?   for instance

typedef struct tagNMHDR {
  HWND     hwndFrom; '8
  UINT_PTR idFrom; '8
  UINT     code; '4
'4 bytes padding
} NMHDR;


the last  4 bytes padding   is automatically added in if we compile to 64bits?




Chris Chancellor

Hello Charles

For example in the below UDT,  the total size = 8 + 4 + 4 = 16

then would O2 compiler pad in another 8 bytes automatically when we compile to 64bits ?



uses  Rtl64

typedef struct myUDT {
  HWND     hwndM; '8
DWORD    myVar1; '4
DWORD    myVar2; '4
} myDat;



Charles Pegge

Hi Chris,

The padding is automatic, and is there to ensure optimal memory alignment of each primitive member.

So an 8+4+4 does not require padding.

You can check the overall size of a UDT with SIZEOF.

Chris Chancellor