Being reading a lot about betterC, but still have some questions

evilrat evilrat666 at gmail.com
Tue Jul 9 08:43:35 UTC 2024


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




More information about the Digitalmars-d-learn mailing list