The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: sinsi on December 31, 2017, 10:30:59 AM

Title: Structure alignment
Post by: sinsi on December 31, 2017, 10:30:59 AM
Within a structure, items should be naturally aligned

structure1 struct
  v32_1    dd ? ;offset 0
           dd ? ;offset 4, padding
  v64_1    dq ? ;offset 8
structure1 ends


Automatically aligned?

structure1 struct 8
  v32_1    dd ? ;offset 0
  v64_1    dq ? ;offset 8
structure1 ends


Should a structure pad the end to align 8?

structure2 struct 8
  v64_1    dq ? ;offset 0
  v32_1    dd ? ;offset 8
           dd ?
structure2 ends


Does alignment only matter within a structure?

var1  dd ?          ;.data? offset 0
str2  structure2 <> ;.data? offset 4 - str2.v64_1 not aligned to 8 - doesn't matter?

Title: Re: Structure alignment
Post by: nidud on December 31, 2017, 11:21:05 AM
deleted
Title: Re: Structure alignment
Post by: sinsi on December 31, 2017, 01:40:05 PM
So memory alignment isn't required but would be more efficient.
Does the -Zp[n] switch override the structure definition?

Would a nested structure need alignment within the main structure?


Thanks for your time.
Title: Re: Structure alignment
Post by: jj2007 on December 31, 2017, 07:19:12 PM
I agree with Nidud that the Zp switch is the way to go. -Zp8 for 64-bit code, to be precise. Everything else is a can of worms.