new T[10] => new T[](10)

dsimcha dsimcha at yahoo.com
Sun Feb 14 14:09:46 PST 2010


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> Now with the full legitimization of statically-sized array, the
> syntactic kludge "new T[10]" is more painful than ever.
> Walter and I were talking about changing the semantics of "new T[10]" to
> mean "allocate a T[10] object and give me a pointer to it" and make the
> syntax "new T[](10)" mean "allocate an array of 10 elements and give me
> a handle to it."
> I see major disruptions of existing code though. Do you guys have ideas
> of a clean migration path?
> Andrei

I'd recommend a simple compiler switch where new T[10] doesn't compile.  You turn
this on when you're porting old code.  When your old code compiles with this
switch on, you know it doesn't have any legacy "new T[10]" stuff in it.  You can
then turn this switch off and start using the new meaning of "new T[10]" if you want.

Also, although I don't care about the breaking of old code (D2 is still alpha and
warts should be fixed no matter how much it hurts backwards compatibility), I
don't see what advantage this more verbose syntax offers.  Why would anyone ever
want to allocate a statically sized array on the heap?  In these cases, what's
wrong with just using a dynamic array?



More information about the Digitalmars-d mailing list