www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Array reference behavior documentation (for Walter)

reply teqDruid <me teqdruid.com> writes:
I noticed a behavior that I didn't expect.  When an array is cast, it
simply changes the pointer type.  An exception is something like the
following:
cast(wchar[])"hello"
which actually makes "hello" a wchar[] array.  Maybe it's just a lack of a
strong C backround (I'm coming from Java) but I didn't expect that
behavior, although I rather like it.

It might be useful for some to have that noted somewhere in the specs, as
I don't recall seeing it there.

John
Jul 11 2004
parent Regan Heath <regan netwin.co.nz> writes:
On Mon, 12 Jul 2004 02:44:10 -0400, teqDruid <me teqdruid.com> wrote:
 I noticed a behavior that I didn't expect.  When an array is cast, it
 simply changes the pointer type.  An exception is something like the
 following:
 cast(wchar[])"hello"
 which actually makes "hello" a wchar[] array.  Maybe it's just a lack of 
 a
 strong C backround (I'm coming from Java) but I didn't expect that
 behavior, although I rather like it.

 It might be useful for some to have that noted somewhere in the specs, as
 I don't recall seeing it there.
I like it too, however, I just made a post to the bugs group saying that this should convert the format of the data in the array, so I'm contradicting myself here when I say... I think it's best if the above is the case, and documented somewhere, if we want to convert the contents/data to a new format then we use a library function. I think this gives us the most flexibility. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 12 2004