Dynamic array creation with default
Michel Fortin
michel.fortin at michelf.com
Wed Aug 24 12:15:54 PDT 2011
On 2011-08-24 11:17:08 +0000, "Steven Schveighoffer"
<schveiguy at yahoo.com> said:
> It's actually possible, but ugly:
>
> auto ptr = (new int[10][](1)).ptr;
>
> One really interesting thing to note -- the compiler actually turns
> struct allocations into array-of-one allocations in the runtime. So
> this is likely what the compiler would do if it supported direct heap
> allocation of fixed-sized arrays.
A problem with this approach is that it won't work in safe mode because
accessing the .ptr property of an array is unsafe in general. But it is
perfectly safe to allocate a static array on the GC heap, so it should
be allowed…
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list