int[3][4]*
Artur Skawina
art.08.09 at gmail.com
Sat Sep 8 04:23:48 PDT 2012
On 09/08/12 05:27, Timon Gehr wrote:
> On 09/08/2012 04:19 AM, bearophile wrote:
>> Ellery Newcomer:
>>
>>> alright what's the deal?
>>
>> This is one of the "clean" ways to do it:
>>
>> void main () {
>> static struct Mat {
>> int[3][4] m;
>> alias m this;
>> }
>> Mat* fooz = new Mat;
>> fooz[1][3] = 5;
>
> This may corrupt your heap.
Yeah, this would be (the) one reason for introducing reference variables
to the language; it's too easy right now to introduce such bugs (and if
the code happens to compile it will just silently return bogus results).
It's a bit late for such a change (and making it more backwards compatible
by having refs that implicitly convert to pointers would be even more
confusing while not solving the problem).
Restricting certain operations on pointers-to-custom-types might work, but
also carries a cost (eg indexing pointers to such types wouldn't be possible
unless via a (temp) slice) as there probably already is code out there that
accesses arrays of indexable-structs via pointers...
artur
More information about the Digitalmars-d-learn
mailing list