digitalmars.D.learn - Example error for initializer?
- Paolo Invernizzi (10/10) Jun 21 2006 Hi all,
- Tom S (9/20) Jun 21 2006 Currently only static arrays can have static initializers, so if you
- Bruno Medeiros (7/21) Jun 22 2006 And by static arrays he means static-storage arrays, and not
- Chris Miller (6/16) Jun 21 2006 DMD doesn't support it yet for non-static, non-const; here is a workarou...
- Chris Nicholson-Sauls (7/32) Jun 21 2006 Or use a templated variadic function. Should be factored out by the opt...
- Chris Miller (7/37) Jun 21 2006 =
Hi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic there's: int[] def = [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static initializer Example error? --- Paolo Invernizzi
Jun 21 2006
Paolo Invernizzi wrote:Hi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic there's: int[] def = [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static initializerCurrently only static arrays can have static initializers, so if you declare the 'def' inside some function, in your case 'main', it must be declared like this: static int[] def = [1, 2, 3]; Declarations at global scope are static anyway, so the error does not occur in that case - and that's the case in the example. -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 21 2006
Tom S wrote:Paolo Invernizzi wrote:And by static arrays he means static-storage arrays, and not static-length arrays. (The term static is ambiguous for arrays. The alternatives for those two are respectively, local-storage, dynamic-length) -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DHi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic there's: int[] def = [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static initializerCurrently only static arrays can have static initializers, so if you
Jun 22 2006
On Wed, 21 Jun 2006 17:01:11 -0400, Paolo Invernizzi = <arathorn NOSPAM_fastwebnet.it> wrote:Hi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic =there's: int[] def =3D [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static =initializer Example error? --- Paolo InvernizziDMD doesn't support it yet for non-static, non-const; here is a workarou= nd: const int[] _def_init =3D [ 1, 2, 3 ]; int[] def =3D _def_init;
Jun 21 2006
Chris Miller wrote:On Wed, 21 Jun 2006 17:01:11 -0400, Paolo Invernizzi <arathorn NOSPAM_fastwebnet.it> wrote:Or use a templated variadic function. Should be factored out by the optimizer and/or inliner (I would imagine). -- Chris Nicholson-SaulsHi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic there's: int[] def = [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static initializer Example error? --- Paolo InvernizziDMD doesn't support it yet for non-static, non-const; here is a workaround: const int[] _def_init = [ 1, 2, 3 ]; int[] def = _def_init;
Jun 21 2006
On Wed, 21 Jun 2006 11:53:26 -0400, Chris Nicholson-Sauls = <ibisbasenji gmail.com> wrote:Chris Miller wrote:On Wed, 21 Jun 2006 17:01:11 -0400, Paolo Invernizzi ==<arathorn NOSPAM_fastwebnet.it> wrote:Hi all, In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic==there's: int[] def =3D [ 1, 2, 3 ]; // dynamic array of 3 ints but does not compile (dmd .0161): variable xdelta.main.def is not a static and cannot have static =initializer Example error? --- Paolo InvernizziDMD doesn't support it yet for non-static, non-const; here is a =workaround: const int[] _def_init =3D [ 1, 2, 3 ]; int[] def =3D _def_init;Or use a templated variadic function. Should be factored out by the =optimizer and/or inliner (I would imagine). -- Chris Nicholson-SaulsMake that T[] array (T) (T[] vals ...) { return vals.dup; } or it refers to old stack memory.
Jun 21 2006