DMD as cross-compiler
Denis Feklushkin
feklushkin.denis at gmail.com
Sun Nov 15 07:21:28 UTC 2020
On Saturday, 14 November 2020 at 19:19:02 UTC, Jacob Carlborg
wrote:
> On Friday, 13 November 2020 at 03:33:05 UTC, Walter Bright
> wrote:
>> On 11/12/2020 11:15 AM, Jacob Carlborg wrote:
>>> Implementing druntime and Phobos without the C standard
>>> library will give a big opportunity to do things better.
>>
>> How so? (Not that you're wrong, I'm just genuinely curious.)
>
> It might not necessary mean a better or different API for
> Phobos. But the lower level APIs could be better.
>
> Classic examples are:
>
> * Use arrays instead of pointers (or pointer length pair).
> `memcpy` would be:
>
> void[] memcpy(void[] source, void[] destination); // I think
> it's more natural to pass the source first
Copying code will be same.
> * Better error handling. I think returning error codes or using
> `errno` is pretty bad error handling strategy. Even though
> exceptions might not be the right choice (unless something like
> this is used [1]), something like returning: `Result!(Value,
> Error)` might be better.
Errno can be covered by druntime like in:
https://dlang.org/phobos/core_memory.html#.pureMalloc
>
> * No global symbols, i.e. not having to worry about conflicting
> names across multiple files
You don't have to worry even now, even if there is a conflict,
this can be resolved by linking settings (I propose to switch
from DUB to Meson :-))
Really, libc is not (only) C library, but de-facto standard for
accessing to OS syscalls. It is possible to drop it but it
doesn't make any sense, it just adds extra work to maintain a
huge compatibility layer for all supported OSes.
I once thought differently, but recently delved deeper into
druntime and looked how it works. In total, I think, there are
about ~15 calls to libc, not so many.
More information about the Digitalmars-d
mailing list