Powerbasic Museum 2020-B

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Chris Chancellor on February 06, 2019, 03:50:19 PM

Title: UDTs are padded out to the size of their largest primitive member
Post by: Chris Chancellor on February 06, 2019, 03:50:19 PM
Hello Charles

in the link at O2 forum

https://www.oxygenbasic.org/forum/index.php?topic=1858.msg20109;topicseen#msg20109 (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?



Title: Re: UDTs are padded out to the size of their largest primitive member
Post by: Chris Chancellor on February 08, 2019, 03:44:28 PM
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;


Title: Re: UDTs are padded out to the size of their largest primitive member
Post by: Charles Pegge on February 15, 2019, 04:50:41 PM
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.
Title: Re: UDTs are padded out to the size of their largest primitive member
Post by: Chris Chancellor on February 23, 2019, 06:06:23 AM
Thanxx a lot  Charles
O2 is very flexible  :)