Multi dimensional array question.

Heywood Floyd soul8o8 at gmail.com
Mon Jul 12 14:23:16 PDT 2010


bearophile Wrote:

> Heywood Floyd:
> > This had me crazy. I ended up putting the brackets on the variable, like
> >   int marr[3][5];
> > then it worked like
> >   marr[2][4] = 9;
> 
> That's present only for compatibility with C syntax, this means that you can use it to perform a quicker port of C code to D, but you are supposed to later convert it to D-style array definitions.
> See also:
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=113185
> 
> Bye,
> bearophile

Aha, good to know! Thanks!
(So this might go away in the future? Or require a -cstyle compile flag?)

***

I have a feeling this "backwards"-array stuff is gonna be one of the things my brain will repel for as long as it can.

To me, it seems equal to saying "you declare a function like:


  void foo(string name, int age){
     //... }
 

And then call it by doing

   foo(90,"Benny")

and this makes sense because the arguments are actually pushed on the stack in reverse at runtime, so they arrive in the correct order in the function. And this is especially important with tuples." or something.

Ok, I understand this has some deep purpose that I still don't understand, I'm just, yeah. *tear*
(Although this is way out of my league: For instance, if a T is an int[3][4], then why can't T[string] be a int[string][3][4], and be accessed with arr["a"][2][3]? Seems just like a matter of taste?)

/HF

PS. I was not the thread creator. I just used the creator's terminology to "stay on topic". Maybe too on topic : ) Not important really. Sorry for the confusion. DS.




More information about the Digitalmars-d-learn mailing list