www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Initializers

reply Sha Chancellor <Sha_member pathlink.com> writes:
Hello,

I would like to accomplish the following:

float[3][4] vertices = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0, -1.0, 0.0],
[1.0, -1.0, 0.0] ];

This does not work, errors about static initializers with nonstatic types.
Great, so vathix tells me to do:

const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,
-1.0, 0.0], [1.0, -1.0, 0.0] ];
float[3][4] vertices = _vertices_init;

This does not work.  Setting it to .dup does not work, slicing it does not work.
The errors are cannot convert float[3][4] to float.  


This is silly, why can't we use an initializer with a non-static types?!
Mar 27 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 27 Mar 2005 22:36:23 +0000 (UTC), Sha Chancellor wrote:

 const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,
 -1.0, 0.0], [1.0, -1.0, 0.0] ];
 float[3][4] vertices = _vertices_init;
Does this help? ... import std.stdio; const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,-1.0, 0.0], [1.0, -1.0, 0.0] ]; void main() { float[3][] vertices = _vertices_init; foreach(int i, float[3] x; vertices) foreach(int j, float y; x) writefln("[%d, %d] = %f", i,j,y); } -- Derek Parnell Melbourne, Australia 28/03/2005 8:47:10 AM
Mar 27 2005
parent reply Sha Chancellor <Sha_member pathlink.com> writes:
Thanks, and my second question:  Why areinitializers for non-static variables
disallowed?  They work in C...

In article <l37tprk1d2m.1tckucfcgfzs$.dlg 40tude.net>, Derek Parnell says...
On Sun, 27 Mar 2005 22:36:23 +0000 (UTC), Sha Chancellor wrote:

 const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,
 -1.0, 0.0], [1.0, -1.0, 0.0] ];
 float[3][4] vertices = _vertices_init;
Does this help? ... import std.stdio; const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,-1.0, 0.0], [1.0, -1.0, 0.0] ]; void main() { float[3][] vertices = _vertices_init; foreach(int i, float[3] x; vertices) foreach(int j, float y; x) writefln("[%d, %d] = %f", i,j,y); } -- Derek Parnell Melbourne, Australia 28/03/2005 8:47:10 AM
Mar 27 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Sun, 27 Mar 2005 23:20:25 +0000 (UTC), Sha Chancellor  
<Sha_member pathlink.com> wrote:
 Thanks, and my second question:  Why areinitializers for non-static  
 variables
 disallowed?  They work in C...
IIRC they will be allowed, Walter just hasn't implemented them yet. Regan
 In article <l37tprk1d2m.1tckucfcgfzs$.dlg 40tude.net>, Derek Parnell  
 says...
 On Sun, 27 Mar 2005 22:36:23 +0000 (UTC), Sha Chancellor wrote:

 const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0,  
 0.0], [-1.0,
 -1.0, 0.0], [1.0, -1.0, 0.0] ];
 float[3][4] vertices = _vertices_init;
Does this help? ... import std.stdio; const float[3][4] _vertices_init = [ [1.0, 1.0, 0.0], [-1.0, 1.0, 0.0], [-1.0,-1.0, 0.0], [1.0, -1.0, 0.0] ]; void main() { float[3][] vertices = _vertices_init; foreach(int i, float[3] x; vertices) foreach(int j, float y; x) writefln("[%d, %d] = %f", i,j,y); } -- Derek Parnell Melbourne, Australia 28/03/2005 8:47:10 AM
Mar 27 2005