digitalmars.D - initializing static rectangular arrays
- llee (7/7) Nov 17 2007 how do you initialize a static multidimensional array? I tried the follo...
- Janice Caron (4/11) Nov 17 2007 Isn't that a 3x3 array, not a 3x4 array?
- llee (9/23) Nov 17 2007 didn't work. I tried:
- naryl (13/37) Nov 17 2007 y.
- Janice Caron (11/19) Nov 17 2007 Yes, because D puts the array dimension on the type, not the variable.
- llee (9/51) Nov 17 2007 thanks for the help. The following worked.
how do you initialize a static multidimensional array? I tried the following, but it did not work. float[3][4] array = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3] ];
Nov 17 2007
On 11/17/07, llee <llee goucher.edu> wrote:how do you initialize a static multidimensional array? I tried the following, but it did not work. float[3][4] array = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3] ];Isn't that a 3x3 array, not a 3x4 array? Anyway, I think the solution to your dilemma is the keyword "const". (Or if that doesn't work, try "static").
Nov 17 2007
Janice Caron Wrote:On 11/17/07, llee <llee goucher.edu> wrote:didn't work. I tried: const float[3][4] elements = [ [1.1, 1.2, 1.3, 1.4], [2.1, 2.2, 2.3, 2.4], [3.1, 3.2, 3.3, 3.4] ]; and the compiler returned "too many initializers" for each nested array.how do you initialize a static multidimensional array? I tried the following, but it did not work. float[3][4] array = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3] ];Isn't that a 3x3 array, not a 3x4 array? Anyway, I think the solution to your dilemma is the keyword "const". (Or if that doesn't work, try "static").
Nov 17 2007
On Sun, 18 Nov 2007 00:54:31 +0300, llee <llee goucher.edu> wrote:Janice Caron Wrote:=On 11/17/07, llee <llee goucher.edu> wrote:how do you initialize a static multidimensional array? I tried the =following, but it did not work.didn't work. I tried: const float[3][4] elements =3D [ [1.1, 1.2, 1.3, 1.4], [2.1, 2.2, 2.3, 2.4], [3.1, 3.2, 3.3, 3.4] =float[3][4] array =3D [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3] ];Isn't that a 3x3 array, not a 3x4 array? Anyway, I think the solution to your dilemma is the keyword "const". (Or if that doesn't work, try "static").]; and the compiler returned "too many initializers" for each nested arra=y. float[3][4] is really an array of 4 arrays of 3 floats. = http://www.digitalmars.com/d/1.0/arrays.html You can initialize it like that: float[3][4] elements =3D [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3] ];
Nov 17 2007
On 11/17/07, naryl <cy ngs.ru> wrote:You can initialize it like that: float[3][4] elements = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3] ];Yes, because D puts the array dimension on the type, not the variable. (But you can do it the C way if you want). So float elements[4][3]; == float[3] elements[4]; == float[3][4] elements; (At least, I think that's right. Disclaimer: I don't have a compiler handy right now).
Nov 17 2007
naryl Wrote:On Sun, 18 Nov 2007 00:54:31 +0300, llee <llee goucher.edu> wrote:thanks for the help. The following worked. const float[3][4] elements = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3] ];Janice Caron Wrote:float[3][4] is really an array of 4 arrays of 3 floats. http://www.digitalmars.com/d/1.0/arrays.html You can initialize it like that: float[3][4] elements = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3], [4.1, 4.2, 4.3] ];On 11/17/07, llee <llee goucher.edu> wrote:didn't work. I tried: const float[3][4] elements = [ [1.1, 1.2, 1.3, 1.4], [2.1, 2.2, 2.3, 2.4], [3.1, 3.2, 3.3, 3.4] ]; and the compiler returned "too many initializers" for each nested array.how do you initialize a static multidimensional array? I tried thefollowing, but it did not work.float[3][4] array = [ [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3] ];Isn't that a 3x3 array, not a 3x4 array? Anyway, I think the solution to your dilemma is the keyword "const". (Or if that doesn't work, try "static").
Nov 17 2007