--- Comment #6 from Don <clugd...@yahoo.com.au> 2010-05-10 07:14:57 PDT ---
(In reply to comment #5)
> Look at this part of the code, which actually writes the void:
> auto r = _d_newarrayT(ti, dim); // r is of type ulong
> p = *cast(void*)(&r);
> This is inside the foo inner function (comment added by me).
> Care must be taken not to set the individual parts of the array because you
> trigger runtime calls.
I still don't see a problem. The only thing that code is doing, is casting from
ulong back to void.
That code should just be:
p = _d_newarrayT(ti, dim);
> I'm not saying that this means casting to/from ulong is the best solution, I'm
> just trying to explain why an actual D array may not be the most suitable type
> to use internally.
> I'm unsure why the foo function uses arrays internally, it clearly takes great
> pains not to trigger any runtime calls by using casting and the ptr member. I
> don't see why it can't do this with the Array struct type instead.
No, that's not the reason for the gymnastics in the code. The code is so old
that when it was originally written, .ptr didn't exist for arrays (.ptr was
added in DMD 0.107). The hack of casting to ulong is recent though (it doesn't
exist in D1), and I think it's a bug.
Although at first the code looks clever and magical, I think it's actually just
an arcane legacy of a time when the language was very primitive and required
lots of hacks.
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------