digitalmars.D.bugs - Initializers
- Sha Chancellor (12/12) Mar 27 2005 Hello,
- Derek Parnell (17/20) Mar 27 2005 Does this help? ...
- Sha Chancellor (3/23) Mar 27 2005 Thanks, and my second question: Why areinitializers for non-static vari...
- Regan Heath (4/37) Mar 27 2005 IIRC they will be allowed, Walter just hasn't implemented them yet.
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
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
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
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. ReganIn 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