Allocating a fixed-size array on the heap
Don Clugston
dac at nospam.com.au
Wed Jan 30 09:54:07 PST 2008
Jarrett Billingsley wrote:
> So, in the process of answering another thread, I realized that it doesn't
> entirely seem possible to allocate a fixed-size array on the heap through
> normal means. That is, the following is legal:
>
> float[4] a;
> float[4]* b = &a;
>
> But:
>
> float[4]* c = new float[4];
>
> "Waiit," says the compiler, "the type of 'new float[4]' is float[]."
>
> So here some syntactic sugar is getting in the way of writing what I mean!
I don't think it's just a syntax sugar problem.
You can write:
alias float[4] Foo;
Foo * c = new Foo;
which generates the error message:
Error: new can only create structs, dynamic arrays or class objects, not float[4u]'s
> Am I missing something or is this just yet another instance of how
> fixed-size arrays aren't treated as first-class citizens?
The error message isn't correct -- you can also 'new' primitive types.
But you can't new an associative array, either; so AAs are also second-class.
More information about the Digitalmars-d
mailing list