Page 1 of 1

Nested structure

Posted: Mon Nov 25, 2024 5:52 am
by Psych
In C you are able to declare a structure union with intelligently defined widths, making byte alignment automatic, however I found no easy way to achieve this in PB unless I define the word pairs in their own named structure

Could we have this?

Code: Select all

Structure WordPair
	StructureUnion
		Structure
			LoWord.w
			HiWord.w
		EndStructure
		Long.l
	EndStructureUnion
EndStructure
Enabling us to access each field with having to qualify the substructure.

Re: Nested structure

Posted: Mon Nov 25, 2024 8:47 am
by STARGĂ…TE
Methode 1:

Code: Select all

Structure LongFields
	Lo.w
	Hi.w
EndStructure

Structure WordPair
	StructureUnion
		LongFields.LongFields
		Long.l
	EndStructureUnion
EndStructure

Define WordPair.WordPair
WordPair\Long = $FF0055AA

Debug Hex(WordPair\LongFields\Lo, #PB_Word)
Debug Hex(WordPair\LongFields\Hi, #PB_Word)
Methode 2:

Code: Select all

Structure WordPair
	StructureUnion
		LongFields.w[0]
		Long.l
	EndStructureUnion
EndStructure

Define WordPair.WordPair
WordPair\Long = $FF0055AA

Debug Hex(WordPair\LongFields[0], #PB_Word)
Debug Hex(WordPair\LongFields[1], #PB_Word)

Re: Nested structure

Posted: Mon Nov 25, 2024 9:43 am
by Demivec