www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - 3 dimensional Array's

reply manfred <manfred_member pathlink.com> writes:
Hello, 

i try to initialize a 3 dimensional Array: 

this example is OK. 
static int  h[2][3][4] = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16],
[17,18,19,20],[21,22,23,24]] ]; 

not OK. 
static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16],
[17,18,19,20],[21,22,23,24]] ]; 

message: 
Error: too many initializers 4 for array[2] 

Is the second example wrong? 

mfg Manfred 
Nov 10 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
(responding to subject)

3 dimensional array is what?  Or to what possession of a 3 dimensional 
array do you refer?

manfred wrote:
<snip>
 not OK. 
 static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16],
 [17,18,19,20],[21,22,23,24]] ]; 
 
 message: 
 Error: too many initializers 4 for array[2] 
 
 Is the second example wrong? 

Yes. When the array dimensions are attached to the type rather than the variable, they go in reverse order. That is, int[2][3][4] is an array of 4 int[2][3]s. You therefore want static int[4][3][2] h = [ [[1,2,3,4], [5,6,7,8], [9,10,11,12]], [[13,14,15,16], [17,18,19,20], [21,22,23,24]] ]; Stewart.
Nov 10 2004
parent manfred <manfred_member pathlink.com> writes:
Thank you. 

In article <cmt14a$1oa8$1 digitaldaemon.com>, Stewart Gordon says... 
 
(responding to subject) 
 
3 dimensional array is what?  Or to what possession of a 3 dimensional  
array do you refer? 
 
manfred wrote: 
<snip> 
 not OK.  
 static int[2][3][4] h = [ [[1,2,3,4],[5,6,7,8],[9,10,11,12]],[[13,14,15,16], 
 [17,18,19,20],[21,22,23,24]] ];  
  
 message:  
 Error: too many initializers 4 for array[2]  
  
 Is the second example wrong?  

Yes. When the array dimensions are attached to the type rather than the variable, they go in reverse order. That is, int[2][3][4] is an array of 4 int[2][3]s. You therefore want static int[4][3][2] h = [ [[1,2,3,4], [5,6,7,8], [9,10,11,12]], [[13,14,15,16], [17,18,19,20], [21,22,23,24]] ]; Stewart.

Nov 10 2004