memcpy() comparison: C, Rust, and D

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 1 13:31:33 PST 2017


On 2/1/2017 9:28 AM, Michael Howell wrote:
> unsafe fn copy_nonoverlapping_ref<T>(src: &T, dest: &mut T, len: usize) {
>   std::ptr::copy_nonoverlapping(src, dest, len)
> }
>
> Again, it doesn't guarantee no side effects, it may guarantee that src isn't
> mutated, it does guarantee that they aren't stored away somewhere, and it
> guarantees that src and dest don't overlap.

What part of the signature guarantees non-overlap?

> It's still unsafe, because it
> doesn't do anything about len being possibly out of bounds, and I left out the
> Copy bound for the sake of flexibility.

Being marked 'unsafe' also includes the ability of the function to save the 
pointers in global variables.



More information about the Digitalmars-d mailing list