Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 178

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 183

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 184

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 220

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 223

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 235

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 250

Deprecated: Function create_function() is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Load.php on line 268
UDTs are padded out to the size of their largest primitive member

Author Topic: UDTs are padded out to the size of their largest primitive member  (Read 441 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 308
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
Quote
UDTs 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?




Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 308
Re: UDTs are padded out to the size of their largest primitive member
« Reply #1 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 ?


Code: [Select]
uses  Rtl64

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


Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
    • Charles Pegge
Re: UDTs are padded out to the size of their largest primitive member
« Reply #2 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.

Offline Chris Chancellor

  • Sr. Member
  • ****
  • Posts: 308
Re: UDTs are padded out to the size of their largest primitive member
« Reply #3 on: February 23, 2019, 06:06:23 AM »
Thanxx a lot  Charles
O2 is very flexible  :)