memcpy() comparison: C, Rust, and D

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 31 15:30:04 PST 2017


On 1/31/2017 3:00 PM, Richard Delorme wrote:
> May we have an example of how the memory safety of arguments supplied to memcpy
> is checked in a way gcc cannot do?
>
> I was thinking of the return attribute, that prevents for example to return the
> address of a local variable through a call to memcpy:

The thing about memcpy is compilers build in a LOT of information about it that 
simply is not there in the declaration. I suggest retrying your example for 
gcc/clang, but use your own memcpy, i.e.:

    void* mymemcpy(void * restrict s1, const void * restrict s2, size_t n);

Let us know what the results are!



More information about the Digitalmars-d mailing list