kirkkaf13@gmail.com wrote: ↑Fri 23 Aug 2024, 21:48
But how can I have a structure with an array of substructures?
The short answer is that you can't. In the case of your specific example, where the array of substructures is the
only member of the parent structure, you can of course simply do this:
But I appreciate that your example was simplified for the purpose of illustration, and that what you would ideally like to do is probably:
Code: Select all
DIM Triangle{points{(2)x,y,z}, other_members}
But this isn't supported in BBC BASIC. The simplest workaround is to separate out the contents into two structures rather than one:
Code: Select all
DIM Triangle_points{(2)x,y,z}
DIM Triangle{other_members}
Personally I don't find this too much of a compromise. The only way to do 'better' (and that's debatable) is to store a
pointer to the array of sub-structures in the main structure, similar to what is described in this
Wiki article. You then end up declaring your structure as follows:
Code: Select all
DIM Triangle{points%%, other_members}
That technique was intended for use when the array member is 'variable length', but is equally applicable if it's an array of structures. Although the code is messy, the messiness is 'hidden away' in procedures (and could even be in a library).