www.digitalmars.com         C & C++   DMDScript  

D - array operations

reply "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I thought you had these in already?

alias float[3] Vc3;
int main(char[][] args)
{
    Vc3 a,b,c;
    a[] =3D b[] + c[];
    return 0;
}
testvector.d(27): Array operations not implemented

And I will need to be able to initialize arrays with array literals, =
such as:

    float[3] up   =3D { 0, 1, 0 };
    float[3] down =3D { 0,-1, 0 };
testvector.d(22): Error: a struct is not a valid initializer for a =
float[3]

This initialization stuff is so fundamental that I can't get far without =
it.  It's very tedious to write:

    float[3] up;
    up[0] =3D 0;
    up[1] =3D 1;
    up[2] =3D 0;

And not only that but it's impossible to initialize global or static =
arrays properly, at point of declaration; you have to do it inside a =
function like main.=20

    Vc3 a,b,c;
    a[0] =3D b[0] + c[0];
    a[1] =3D b[1] + c[1];
    a[2] =3D b[2] + c[2];
    return 0;
If I wanted to do that I would use C.

Bother.

Maybe I'll try overloading my own operators, see if that works yet.

Sean
Oct 19 2002
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

try

    float[3] up   =3D [ 0, 1, 0 ];
    float[3] down =3D [ 0,-1, 0 ];
  "Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message =
news:aos8r1$2hbf$1 digitaldaemon.com...

  And I will need to be able to initialize arrays with array literals, =
such as:

      float[3] up   =3D { 0, 1, 0 };
      float[3] down =3D { 0,-1, 0 };
  testvector.d(22): Error: a struct is not a valid initializer for a =
float[3]
Oct 19 2002
parent reply "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

You're right, but in the Examples under Array Operations it says:

int[] def =3D { 1, 2, 3 };	// dynamic array of 3 ints

This is dynamic array instead of normal but should be same syntax, =
right?

Sean
  "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message =
news:aosd4a$2l97$1 digitaldaemon.com...
  try

      float[3] up   =3D [ 0, 1, 0 ];
      float[3] down =3D [ 0,-1, 0 ];
    "Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message =
news:aos8r1$2hbf$1 digitaldaemon.com...

    And I will need to be able to initialize arrays with array literals, =
such as:

        float[3] up   =3D { 0, 1, 0 };
        float[3] down =3D { 0,-1, 0 };
    testvector.d(22): Error: a struct is not a valid initializer for a =
float[3]
Oct 19 2002
parent "Walter" <walter digitalmars.com> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

The example is wrong, it should be [], not {}. -Walter
  "Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message =
news:aosm19$2u69$1 digitaldaemon.com...
  You're right, but in the Examples under Array Operations it says:

  int[] def =3D { 1, 2, 3 }; // dynamic array of 3 ints

  This is dynamic array instead of normal but should be same syntax, =
right?

  Sean
    "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message =
news:aosd4a$2l97$1 digitaldaemon.com...
    try

        float[3] up   =3D [ 0, 1, 0 ];
        float[3] down =3D [ 0,-1, 0 ];
      "Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message =
news:aos8r1$2hbf$1 digitaldaemon.com...

      And I will need to be able to initialize arrays with array =
literals, such as:

          float[3] up   =3D { 0, 1, 0 };
          float[3] down =3D { 0,-1, 0 };
      testvector.d(22): Error: a struct is not a valid initializer for a =
float[3]
Nov 12 2002