Jump to page: 1 2
Thread overview
Being reading a lot about betterC, but still have some questions
Jul 09
kiboshimo
Jul 09
evilrat
Jul 09
kiboshimo
Jul 09
kiboshimo
Jul 09
Sergey
Jul 09
kiboshimo
Jul 09
kiboshimo
Jul 09
monkyyy
Jul 09
kiboshimo
Jul 10
kiboshimo
Jul 10
kiboshimo
Jul 10
kiboshimo
Jul 09
monkyyy
July 09
Hi,

Some stuff must look obvious to an experienced programmer so they are not explicit on articles and documentation over the internet. I'm somewhat inexperienced, so:

- betterC does not need glue code to interop with C. Does it achieve this by "gluing" behind the scenes? I've read in a comment somewhere that the ABI is the same, but idk people say lots of things.

- betterC cannot be used with some parts of phobos. Should I worry I won't be able to use essential stuff for systems programming? Things like atomics.
// If that is the case, can I supplant these low-level stuff with an equivalent C library? (I don't think so, but I'm hopefull).

- betterC can be compiled to WASM, but some of phobos can't, so basically same worries as above. I'm afraid to lose some essential systems stuff that I could not replace.

I'm going to try a project with raylib and WASM. Really liked the idea of doing it with betterC to start my systems programming journey (tough start, don't care, just fill me in if you want to).

Thanks :)
July 09

On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote:

>

Hi,

Some stuff must look obvious to an experienced programmer so they are not explicit on articles and documentation over the internet. I'm somewhat inexperienced, so:

  • betterC does not need glue code to interop with C. Does it achieve this by "gluing" behind the scenes? I've read in a comment somewhere that the ABI is the same, but idk people say lots of things.

  • betterC cannot be used with some parts of phobos. Should I worry I won't be able to use essential stuff for systems programming? Things like atomics.
    // If that is the case, can I supplant these low-level stuff with an equivalent C library? (I don't think so, but I'm hopefull).

  • betterC can be compiled to WASM, but some of phobos can't, so basically same worries as above. I'm afraid to lose some essential systems stuff that I could not replace.

I'm going to try a project with raylib and WASM. Really liked the idea of doing it with betterC to start my systems programming journey (tough start, don't care, just fill me in if you want to).

Thanks :)

betterC is just a reduced D subset that was intended to help porting C code over to D to an unsupported platforms where the full D runtime (provides GC and other advanced language features) is not yet implemented or not feasible (like microcontrollers, although D is not very friendly to 8-bit hardware).

Because it turns off many advanced features it means there is no GC and runtime type information(RTTI), many of the phobos functions relies on these features.

All this makes it very advanced feature not intended for mass users.

  • Don't confuse it with extern(C) linkage too, extern(C) is what makes it compatible with C ABI.

  • Don't confuse it with an importC feature.

  • It is not betterC to blame for lacking standard library support but because phobos is not implemented for it, of course you can do it yourself if you really wanted to but certain D concepts (like ranges) will be much harder to do without GC support.

  • You can't have regular D classes (extern(D)) in betterC as they rely on RTTI, however you can have extern(C++) classes.

  • If your C/C++ library provides atomics, you can do this, but probably you can use some of the phobos as this is pretty low level stuff.


What it is:

  • reduced language subset to allow "easier" targeting to very modest hardware or other unsupported systems
  • it makes the compiler emits errors if you accidentally use some of full D features

What it is NOT:

  • it is not a C compiler
  • it won't accept your C files as if it is D
  • it won't just magically port C code for you
July 09
On 09/07/2024 8:43 PM, evilrat wrote:
> - If your C/C++ library provides atomics, you can do this, but probably you can use some of the phobos as this is pretty low level stuff.

Atomics are provided by the compiler in the form of intrinsics.

If you do not do this, they cannot be inlined as you're forced to use inline assembly.

LDC and GDC like GCC and clang have an intrinsic based implementation for ``core.atomics``. DMD is the only D compiler that uses inline assembly currently.

It is all templated so yes it is accessible within a -betterC codebase.
July 09
Thank you for the comprehensive responses

On 09/07/2024 8:43 PM, Richard (Rikki) Andrew Cattermole wrote:
> Atomics are provided by the compiler in the form of intrinsics.
>
> If you do not do this, they cannot be inlined as you're forced to use inline assembly.
>
> LDC and GDC like GCC and clang have an intrinsic based implementation for ``core.atomics``. DMD is the only D compiler that uses inline assembly currently.
>
> It is all templated so yes it is accessible within a -betterC codebase.

That is good to know. I should expect this kind of feature to be present, after all betterC must be a working subset of D. But, I wasn't sure enough.

Based on the responses I'm assuming my example of atomic is a special case, but I shouldn't worry about low level things like threads to be absent all the same.

That's betterC targeting native. What about WASM? Does LDC -> WASM pipeline supports functionality one needs in a C-level language? If not, aside from atomics, one should be able to use C libraries to supplant any other purpose, right? Since C has mature support for WASM.
July 09
On 09/07/2024 9:27 PM, kiboshimo wrote:
> Based on the responses I'm assuming my example of atomic is a special case, but I shouldn't worry about low level things like threads to be absent all the same.

Threads are indeed gone.

That is library code in druntime that needs to be linked in along with the GC.

If you want them, you'll have to call out to the system API and do your own thing.

> That's betterC targeting native. What about WASM? Does LDC -> WASM pipeline supports functionality one needs in a C-level language? If not, aside from atomics, one should be able to use C libraries to supplant any other purpose, right? Since C has mature support for WASM.

I cannot comment about web assembly since I haven't done anything there, but some people have so hopefully they'll comment about where to go from here.
July 09
On Tuesday, 9 July 2024 at 09:27:30 UTC, kiboshimo wrote:
> That's betterC targeting native. What about WASM? Does LDC -> WASM pipeline supports functionality one needs in a C-level language? If not, aside from atomics, one should be able to use C libraries to supplant any other purpose, right? Since C has mature support for WASM.

Feel free to join our Discord chat.
Some info is saved there. Also many active authors of D libraries (including related to the betterC and WASM) are there as well
July 09
On Tuesday, 9 July 2024 at 09:30:18 UTC, Richard (Rikki) Andrew Cattermole wrote:
> Threads are indeed gone.

Oh no.

>If you want them, you'll have to call out to the system API and do your own thing.

I hope "doing my own thing here" could be linking to a C library that interacts with the OS on my behalf.

> I cannot comment about web assembly since I haven't done
> anything there, but some people have so hopefully they'll
> comment about where to go from here.

Some of them might know. And if they know, them I will know. And if I know, then, you know...



July 09
On Tuesday, 9 July 2024 at 09:42:01 UTC, Sergey wrote:
> Feel free to join our Discord chat.
> Some info is saved there. Also many active authors of D libraries (including related to the betterC and WASM) are there as well

Already did, will try the search bar later. Sun is rising over here and I've not slept yet. Thank you :)

July 09

On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote:

If you haven't done so, I'd recommend reading the blog posts from Walter to get an understanding of why BetterC was introduced and how to use it: https://dlang.org/blog/category/betterc/

>
  • betterC does not need glue code to interop with C. Does it achieve this by "gluing" behind the scenes? I've read in a comment somewhere that the ABI is the same, but idk people say lots of things.

You're declaring your D code extern(C), as you can see in Walter's blog posts, so yes, you're using the C ABI.

July 09
On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote:
> I'm going to try a project with raylib and WASM.

use mine

https://github.com/crazymonkyyy/raylib-2024/blob/master/docs/examplecode.md

> - betterC can be compiled to WASM, but some of phobos can't, so basically same worries as above. I'm afraid to lose some essential systems stuff that I could not replace.

yes, and your not afraid enough

> Really liked the idea of doing it with betterC to start my systems programming journey

Theres nothing even slightly pleasant or easy about d's wasm "support"; I wrote my own cos, sqrt functions, you get *nothing* from phoboes
« First   ‹ Prev
1 2