Passing dynamic arrays
Daniel Gibson
metalcaedes at gmail.com
Mon Nov 8 10:35:38 PST 2010
bearophile schrieb:
> Jens Mueller:
>
>> I find this behavior rather strange.
>
> I don't know if it's strange, but surely it is a little bug-prone corner of D. I have had two or three bugs in my code because of that.
>
If you pass a dynamic array to a function and chance it's size within the
function, you have undefined behaviour - you never know if it will affect the
original array (from the calling function) or not.
So IMHO a compiler warning would be appropriate in that case.
(It would be even better to have more consistent array handling throughout the
different kinds of arrays, as I wrote in another branch of this thread, but if
that is no option, for example because it contradicts TDPL, a compiler warning
is a good compromise)
Cheers,
- Daniel
More information about the Digitalmars-d
mailing list