[Issue 6421] Require initialization of static arrays with array literals not to allocate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 4 01:43:51 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=6421

Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich at gmail.com

--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
With recent changes we can now use this syntax for initialization of a
variable:

-----
void main()
{
    float x = float(1.0);
}
-----

And in OpenGL, you can use this syntax for array initializers:

-----
float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
-----

So this got me thinking, the initializer looks very much like the new
initializer in D that we introduced. With a parser fix we could implement this
in D:

-----
void main()
{
    float[3] arr = float[3](1.0, 2.0, 3.0);
}
-----

Even though Issue 2356 is fixed the above might help in some other contexts,
perhaps in array appends.

--


More information about the Digitalmars-d-bugs mailing list