Can't implement conformant memset/memcpy without compiler -ffreestanding support

rikki cattermole rikki at cattermole.co.nz
Wed Jul 25 09:35:00 UTC 2018


On 25/07/2018 9:23 PM, Zheng (Vic) Luo wrote:
> On Wednesday, 25 July 2018 at 09:16:19 UTC, rikki cattermole wrote:
>> On 25/07/2018 8:59 PM, Zheng (Vic) Luo wrote:
>>> Minimal example in D: https://run.dlang.io/is/EYVTzb. Affects at 
>>> least dmd and ldc.
>>>
>>
>> https://run.dlang.io/is/8tPOVX
>>
>> Note that switch void* to ubyte* won't matter once its extern(C)'d.
>>
>> My version (_memcpy_impl2) is just the regular old memcpy without 
>> optimizations. Your example is syntax sugar for a function call.
> 
> There is no guarantee that a compiler (in a future version or after 
> enabling some optimization flags) will not optimize _memcpy_impl2 into 
> "call memset". Maybe it just happens that the optimizer is not smart 
> enough to optimize this, because nothing with -beeterC prohibits the 
> compiler to do so.

You misunderstand.
It isn't optimizing anything.
You requested the call to memcpy, explicitly when you said 'I want this 
copied ASAP'.

By the looks, the spec doesn't clearly explain this properly.


More information about the Digitalmars-d mailing list