www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - So many years I was following D...

reply Iamgottingcrazy <shouldIlearnthis digitalmars.com> writes:
Should I bear this??

module teststructarray;

import std.stdio;
import core.stdc.stdlib:system;

struct Point
{
  int x;
  int y;
}
static Point[2] pArray1=
[
  {0,0},{0,1},//watch here!
];

static Point pArray2[2][3]=
[
  [{0,0},{0,1},{0,2}],
  [{1,0},{1,1},{1,2}],//watch here,without the last comma,the prog can't get
compiled!!
];
void main()
{
  foreach(int i,point;pArray1)
    writefln("Point(%d)={%d,%d}",i,pArray1[i].x,pArray1[i].y);
  
  foreach(points;pArray2)
  {
    foreach(point;points)
    {
      writef("Point(%d,%d)\t",point.x,point.y);
    }
    write("\n");
  }
  system("pause");//watch when this line gets executed
}

Try compile and run.
Oct 14 2009
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Iamgottingcrazy:

 Should I bear this??
With D1 it seems to work: http://codepad.org/hpslrHHs Bye, bearophile
Oct 14 2009
next sibling parent Fawzi Mohamed <fmohamed mac.com> writes:
On 2009-10-14 10:48:10 +0200, bearophile <bearophileHUGS lycos.com> said:

 Iamgottingcrazy:
 
 Should I bear this??
With D1 it seems to work: http://codepad.org/hpslrHHs Bye, bearophile
maybe because you actually used the correct sequence of dimensions... int[2][3] x; x.length is 3, this is a 3 dimensional array of 2 dimensional arrays... Fawzi
Oct 14 2009
prev sibling parent "AJ" <aj nospam.net> writes:
bearophile wrote:
 Iamgottingcrazy:

 Should I bear this??
With D1 it seems to work: http://codepad.org/hpslrHHs Bye, bearophile
He had a technical problem and worded his subject line that way?
Oct 16 2009
prev sibling parent Gide Nwawudu <gide btinternet.com> writes:
On Wed, 14 Oct 2009 04:26:38 -0400, Iamgottingcrazy
<shouldIlearnthis digitalmars.com> wrote:

Should I bear this??

module teststructarray;

import std.stdio;
import core.stdc.stdlib:system;

struct Point
{
  int x;
  int y;
}
static Point[2] pArray1=
[
  {0,0},{0,1},//watch here!
];

static Point pArray2[2][3]=
[
  [{0,0},{0,1},{0,2}],
  [{1,0},{1,1},{1,2}],//watch here,without the last comma,the prog can't get
compiled!!
];
void main()
{
  foreach(int i,point;pArray1)
    writefln("Point(%d)={%d,%d}",i,pArray1[i].x,pArray1[i].y);
  
  foreach(points;pArray2)
  {
    foreach(point;points)
    {
      writef("Point(%d,%d)\t",point.x,point.y);
    }
    write("\n");
  }
  system("pause");//watch when this line gets executed
}

Try compile and run.
Looks like a version of the following bug. http://d.puremagic.com/issues/show_bug.cgi?id=2477 Gide
Oct 14 2009