On 11/27/2017 10:47 AM, Dmitry wrote:
> On Monday, 27 November 2017 at 18:40:41 UTC, Ali Çehreli wrote:
>
>> So, it looks like the original code was accessing out of bounds and
>> probably that's why you inserted the ((index + 3) < N) check in the D
>> version because D was catching that error at runtime.
> Yes, it is.

This is exactly the kind of bug Walter wanted to avoid when leaving C's arrays behind. (This includes C++'s std::vector because vector::operator[] is permissive. (To be safe, one needs to use .at() or check indexes explicitly.))

So, as advertised, port your programs to D and the results will likely be more correct. I like it! :)

Ali

P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements:

// C++
void alpha_bleeding(unsigned char *image, int width, int height)

// D
private void alphaBleeding(ref ubyte[] data, int width, int height)

You would need that 'ref' if you wanted to modify the original array itself by e.g. adding elements to it.

Reply via email to