Tried C++ to D. Wrong result.
Ali Çehreli
acehreli at yahoo.com
Mon Nov 27 19:01:28 UTC 2017
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.
More information about the Digitalmars-d-learn
mailing list