Jump to page: 1 24  
Page
Thread overview
DMD 0.167 release
Sep 18, 2006
Walter Bright
Sep 18, 2006
Juan Jose Comellas
Sep 18, 2006
Frits van Bommel
Sep 18, 2006
Walter Bright
Sep 18, 2006
Walter Bright
Sep 18, 2006
clayasaurus
Sep 18, 2006
Walter Bright
Sep 18, 2006
clayasaurus
Sep 18, 2006
Walter Bright
Sep 20, 2006
Knud Sørensen
Sep 20, 2006
Reiner Pope
Sep 18, 2006
Walter Bright
Sep 18, 2006
Walter Bright
Sep 18, 2006
Stewart Gordon
Sep 18, 2006
Walter Bright
Sep 18, 2006
Pragma
Sep 18, 2006
David Medlock
Sep 18, 2006
Sean Kelly
Sep 18, 2006
%u
Sep 19, 2006
Derek Parnell
Sep 19, 2006
Walter Bright
Sep 19, 2006
Lionello Lunesu
Sep 19, 2006
Serg Kovrov
Sep 19, 2006
Serg Kovrov
Sep 19, 2006
Ivan Senji
Sep 19, 2006
Don Clugston
Sep 19, 2006
Kyle Furlong
Sep 19, 2006
Walter Bright
Sep 19, 2006
David Medlock
Sep 20, 2006
Fredrik Olsson
Sep 20, 2006
Kyle Furlong
Sep 20, 2006
Chad J
September 18, 2006
Array literals, by popular demand.

http://www.digitalmars.com/d/changelog.html
September 18, 2006
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
"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
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
"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
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
Jarrett Billingsley wrote:
> And I guess you're still updating the docs. 

They are uploaded now.
September 18, 2006
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
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
"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.


« First   ‹ Prev
1 2 3 4