An unfortunate "misfeature"

0ffh frank at frankhirsch.youknow.what.todo.net
Mon Dec 24 04:48:39 PST 2007


Hxal wrote:
> Personally I'd be happy if array literals were allocated in the
> read-only data section and on the stack (for dynamic initializers).
> There's always the [1, 2, 3].dup syntax for allocating on the heap. But
> that kind of change might break a lot of existing code.

Actually I don't see how it would break anything, if the compiler uses a
different initialisation function specifically in the case of declaring
and initialising a variable (which is a compromise, but hey! =).

That'd mean to have "int[2] x=[1,2];" call a special initialiser, while
other use-cases for constant array retained the current behaviour, which
can admittedly be argued to be more tentative (probably trying to not
let you shoot your own foot).

BTW probably the compromise could be better, but a deeper analysis of
the possibilities would be needed to find the best practical one.

I must admit that I'd personally prefer the more general and clear cut
(and, alas, disruptive) "[]" vs "[].dup" syntax.

regards, frank



More information about the Digitalmars-d mailing list