There are times when you may need a structure to be NOT padded (i.e. not aligned, as is standard), and others where you NEED it padded. So we can't ask Fred to change the default operation. However, you can do this manually with a macro and StructureUnion.
I just thew this together quickly, so I'll leave the tuning of this to the coder who requires the alignment padding. This code appears to work with w7-32:
Code: Select all
; Macro to pad a variable in a structure to a minimum length
Macro PaddedVar(name, type, bytes)
StructureUnion
_#name#bytes.s{bytes}
name#.type
EndStructureUnion
EndMacro
Structure Test1
PaddedVar(a, w, 8)
PaddedVar(b, w, 8)
c.w
d.w
EndStructure
testvar.Test1
testvar\a = 5
testvar\b = 88
testvar\c = 6
testvar\d = 77
Debug @testvar\a
Debug @testvar\b
Debug @testvar\c
Debug @testvar\d
; Test regular non-padded structure:
Debug "-----"
Structure Test2
a.w
b.l
c.w
d.w
EndStructure
testvar2.Test2
testvar2\a = 5
testvar2\b = 88
testvar2\c = 6
testvar2\d = 77
Debug @testvar2\a
Debug @testvar2\b
Debug @testvar2\c
Debug @testvar2\d
Of course, if you knew ahead of time that all of your structs would have the same alignment, you could eliminate one macro argument and replace it with a constant...
Code: Select all
; This variation uses a fixed padding value,
; so there are only two macro arguments.
; Macro to pad a variable in a structure to a minimum length
Macro PaddedVar(name, type)
StructureUnion
_#name#bytes.s{#PaddedVarSize}
name#.type
EndStructureUnion
EndMacro
; Size of padded variables
#VarSizeb = 1
#VarSizea = 1
CompilerIf #PB_Compiler_Unicode = 1
#VarSizec = 2
CompilerElse
#VarSizec = 1
CompilerEndIf
#VarSizew = 2
#VarSizeu = 2
#VarSizel = 4
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#VarSizei = 4
CompilerElse
#VarSizei = 8
CompilerEndIf
#VarSizef = 4
#VarSizeq = 8
#VarSized = 8
; Demo the macro...
#PaddedVarSize = #VarSizeq
Structure Test1
PaddedVar(a, w)
PaddedVar(b, w)
c.w
d.w
EndStructure
testvar.Test1
testvar\a = 5
testvar\b = 88
testvar\c = 6
testvar\d = 77
Debug @testvar\a
Debug @testvar\b
Debug @testvar\c
Debug @testvar\d