Multi Dimension Static array inside Structure

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Multi Dimension Static array inside Structure

Post 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
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

This is an old request. Search is good sometimes 8)
http://www.purebasic.fr/english/viewtopic.php?t=15752
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Ah, I searched for the phrase "multidimensional". Mind you, the thread I found is 3 years old!
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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". :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Damn it!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Post 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)
Post Reply