Thread overview | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 18, 2006 DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Array literals, by popular demand. http://www.digitalmars.com/d/changelog.html |
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Thanks! Has the documentation on the digitalmars.com site been updated? I can't find the section for array literals.
Walter Bright wrote:
> Array literals, by popular demand.
>
> http://www.digitalmars.com/d/changelog.html
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound@digitalmars.com> wrote in message news:eemqtr$1iaj$1@digitaldaemon.com... > Array literals, by popular demand. > > http://www.digitalmars.com/d/changelog.html o Added support for multidimensional array allocation with NewExpression. o Added array literals. o std.format will now work with struct arguments as long as they define a char[] toString() member function. Three very, very tasty new features. Thank you so much :) And I guess you're still updating the docs. |
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juan Jose Comellas | First of all, thank you Walter. Those look like some great features. And bugfixes are always good too :).
Juan Jose Comellas wrote:
> Thanks! Has the documentation on the digitalmars.com site been updated? I
> can't find the section for array literals.
Looks like it isn't updated on the site yet, but it's in the package: dmd/html/d/expression.html. The relevant quote:
Array Literals
Array literals are a comma-separated list of
AssignExpressions between square brackets [ and ]. The
AssignExpressions form the elements of a static array,
the length of the array is the number of elements. The
type of the first element is taken to be the type of all
the elements, and all elements are implicitly converted
to that type.
[1,2,3]; // type is int[3], with elements 1, 2 and 3
[1u,2,3]; // type is uint[3], with elements 1u, 2u, and 3u
One question about the above: When an array literal is used in the code, is the resulting array allocated on the stack?
I ask because it doesn't mention using dynamic memory allocation, nor does it mention the array being unusable after the scope ends...
(Since it allows AssignExpressions -- not just constants -- it can't generally be statically allocated, right?)
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:eemsjf$1l1a$1@digitaldaemon.com... > "Walter Bright" <newshound@digitalmars.com> wrote in message news:eemqtr$1iaj$1@digitaldaemon.com... >> Array literals, by popular demand. >> >> http://www.digitalmars.com/d/changelog.html > > o Added support for multidimensional array allocation with NewExpression. > o Added array literals. > o std.format will now work with struct arguments as long as they define a > char[] toString() member function. > > Three very, very tasty new features. Thank you so much :) > > And I guess you're still updating the docs. Don't know if this is a bug.. void fork(int[] x) { foreach(i; x) writefln(i); } .. fork([1, 2, 3]); That works fine. But: int[] x = [1, 2, 3]; Fails, since "x is not a static and cannot have static initializer." Maybe that detection has to be removed? |
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | Frits van Bommel wrote:
> One question about the above: When an array literal is used in the code, is the resulting array allocated on the stack?
> I ask because it doesn't mention using dynamic memory allocation, nor does it mention the array being unusable after the scope ends...
> (Since it allows AssignExpressions -- not just constants -- it can't generally be statically allocated, right?)
It's allocated on the heap.
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> And I guess you're still updating the docs.
They are uploaded now.
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Array literals, by popular demand.
>
> http://www.digitalmars.com/d/changelog.html
Why isn't
int bob[] = [2,3] allowed but
int bob[]; bob = [2,3]
is allowed?
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | clayasaurus wrote:
> Walter Bright wrote:
>> Array literals, by popular demand.
>>
>> http://www.digitalmars.com/d/changelog.html
>
> Why isn't
>
> int bob[] = [2,3] allowed but
>
> int bob[]; bob = [2,3]
>
> is allowed?
A bug? <g>
|
September 18, 2006 Re: DMD 0.167 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound@digitalmars.com> wrote in message news:eemulj$1ogm$1@digitaldaemon.com... > Frits van Bommel wrote: > It's allocated on the heap. To expand upon this, something like fork([1, 2, 3]); is turned into something like fork(_d_arrayliteral(1, 2, 3)); That is, it's a function call. _d_arrayliteral creates a new array on the heap and copies its variadic arguments into it. |
Copyright © 1999-2021 by the D Language Foundation