Page 1 of 1
Multi Dimension Static array inside Structure
Posted: Sun Sep 10, 2006 2:47 am
by Guimauve
Multi Dimension Static array inside Structure can be programmed like this:
Code: Select all
Structure Vector4D
Coords.d[4]
EndStructure
Structure Matrix4X4
Line.Vector4D[4]
EndStructure
It's little bit ugly. But like this
Code: Select all
Structure Matrix4X4
Number.d[4, 4]
EndStructure
or like this
Code: Select all
Structure Matrix4X4
Number.d[4][4]
EndStructure
it's more clear and easy to use.
Regards
Guimauve
Posted: Sun Sep 10, 2006 4:17 am
by Shannara
Reference:
http://www.purebasic.fr/english/viewtop ... ture+array
Hellos,
This was requested on April 28, 2004. So far, there was no answer from the developers.
Posted: Wed Jan 14, 2009 8:48 am
by Seymour Clufley
Is there a special reason why PB doesn't allow multidimensional arrays in structures, or is it just something that hasn't been implemented yet? I ask because it would be an extremely useful addition to PB, IMHO.
Posted: Wed Jan 14, 2009 11:06 am
by srod
Well, for use with api functions (many of which require static arrays within the structures etc); these structures need to be 'what you see is what you get'! Allowing multi-dimensional arrays would require PB to store info on the bounds of each dimension in order to be able to reference individual elements etc. Where would PB store this info? If it stored it within the structure itself then we could no longer use the structure in api functions etc. Prohibiting PB from storing this data would effectively force such arrays to remain static so that all calculations with the array bounds can be undertaken at compile-time rather than run-time, and a static multi-dimensional array is really no easier to use than a single dimensional one!
Of course an alternative is to keep the existing static arrays for compatability with api functions, but add say dynamic arrays etc. as a completely new type of structure field. That would definitely be useful. At the moment I use one of my own utilities for this, but it would be useful to have this as native PB commands for sure!

Posted: Wed Jan 14, 2009 4:24 pm
by Psychophanta
Posted: Wed Jan 14, 2009 5:18 pm
by Seymour Clufley
Ah, I searched for the phrase "multidimensional". Mind you, the thread I found is 3 years old!
Posted: Wed Jan 14, 2009 9:36 pm
by Psychophanta
Seymour Clufley wrote:Ah, I searched for the phrase "multidimensional". Mind you, the thread I found is 3 years old!
Too difficult. To do it simpler, you had to search just for "dimension".

Posted: Thu Jan 15, 2009 3:56 am
by Seymour Clufley
Damn it!
Posted: Sun Jan 18, 2009 12:41 am
by STARGĂ…TE
you can use a Macro to help:
Code: Select all
Structure Array1
Field.d[10]
EndStructure
Structure Array2
Field.Array1[10]
EndStructure
Macro Field(x,y)
Field[x]\Field[y]
EndMacro
MultiDimension.Array2
MultiDimension\Field(1,1) = 4
Debug MultiDimension\Field(1,1)