An unfortunate "misfeature"
0ffh
frank at frankhirsch.youknow.what.todo.net
Mon Dec 24 04:10:19 PST 2007
Assertion:
Initialising a stack variable shouldn't allocate heap memory.
Observation:
I have recently got the impression that this code
void bar(int a,int b)
{
int[2] arr=[a,b];
[...]
}
allocates heap memory, although we are initialising a variable
which does not end up on the heap, but on the stack (DMD1).
Suggestion:
I'd hope it would be possible to use a different initialisation
function for assigning array literals to static arrays.
The slightly ambivalent case
void bar(int a,int b)
{
auto arr=[a,b];
[...]
}
would of course have a well documented default behaviour. Currently
it's a static array on the stack (not a dynamic array on the heap).
I think this could be called fixing a misfeature.
regards, frank
More information about the Digitalmars-d
mailing list