Example error for initializer?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Jun 21 08:53:26 PDT 2006
Chris Miller wrote:
> On Wed, 21 Jun 2006 17:01:11 -0400, Paolo Invernizzi
> <arathorn at NOSPAM_fastwebnet.it> 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
>> initializer
>>
>> Example error?
>>
>> ---
>> Paolo Invernizzi
>
>
> DMD 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;
Or use a templated variadic function. Should be factored out by the optimizer and/or
inliner (I would imagine).
# T[] array (T) (T[] vals ...) { return vals; }
#
# int[] def = array(1, 2, 3);
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list