digitalmars.D - new T[10] => new T[](10)
- Andrei Alexandrescu (9/9) Feb 14 2010 Now with the full legitimization of statically-sized array, the
- dsimcha (10/19) Feb 14 2010 I'd recommend a simple compiler switch where new T[10] doesn't compile. ...
- Steven Schveighoffer (14/42) Feb 15 2010 A dynamic array consists of 2 elements, a length and a pointer. If you ...
- BCS (10/21) Feb 14 2010 I'm not seeing a problem.
- Stewart Gordon (6/8) Feb 15 2010 Make "new T[10]" a doubly-typed expression. T[] or T[10]* depending on
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
Feb 14 2010
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s articleNow 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? AndreiI'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?
Feb 14 2010
On Sun, 14 Feb 2010 17:09:46 -0500, dsimcha <dsimcha yahoo.com> wrote:== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s articleA dynamic array consists of 2 elements, a length and a pointer. If you never change the length, that's a lot of wasted bytes and passing around of data if you never change it. Also, the current interpretation makes generic code more difficult. It makes statically sized arrays different than all other value types. Just for that reason, it's worth the change. If you're going to make the argument that new int[x] is a dynamic array, then I'd argue that new int[x][y][z] should not have any static arrays anywhere. Having new int[x][y][z] make only the z dimension a dynamic array is madness. I think the proposed fix is the most sane and consistent possible. -SteveNow 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? AndreiI'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?
Feb 15 2010
Hello Andrei,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?I'm not seeing a problem. given: new T[exp] If exp is not a compile time constant, return a dynamic-sized array of the runtime evaluated value. else return a statically-sized array that can be implicitly converted to a dynamic-sized array. The only problem I see is: how would this interact with CTFE? -- <IXOYE><
Feb 14 2010
Andrei Alexandrescu wrote: <snip>I see major disruptions of existing code though. Do you guys have ideas of a clean migration path?Make "new T[10]" a doubly-typed expression. T[] or T[10]* depending on what you try to do with it. But which should be the default type? Stewart.
Feb 15 2010