by blazemaster · 7y ago · 0 comments
In this mode, no GC is provided, so a developer will be using manual allocation.
With upcoming D's dip1000 feature, it will be able to do rust-like borrows checker at compile time (or at least this is my understanding). And that capability will be available in betterC mode as well (not just for full blown D).
The code in betterC can use generics and other advanced features
https://dlang.org/spec/betterc.html
---
Nearly the full language remains available. Highlights include:
- Unrestricted use of compile-time features
- Full metaprogramming facilities
- Nested functions, nested structs, delegates and lambdas
- Member functions, constructors, destructors, operating overloading, etc.
- The full module system
- Array slicing, and array bounds checking
- RAII (yes, it can work without exceptions) scope(exit)
- Memory safety protections
- Interfacing with C++
- COM classes and C++ classes
- assert failures are directed to the C runtime library
- switch with strings
- final switch
- unittest
dip1000:
https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000...
Though TBH i wouldn't use OP's preprocessor either as i think that void* and macros are perfectly fine.
Heck, you could define a few macros and make it impossible to use any baggage features you don't like.
I've used C++ in a pretty tight embedded environment and it was great.
I'd love to hear some details. I'm always looking for C++ stories that didn't end in disaster and what the people did that worked.
It is quite do-able. Lots of static declarations, basically write C with classes. V-tables ended up being non-trivial in size, but what can you do, GUIs and all that. Possibly the best (only?) good use of inheritance hierarchies.
256KB memory, the UI only had 60KB or so available for it IIRC. We also had a scratch pad available over a super slow bus of a couple megs, but it couldn't be used too much or we'd drop frames and we loved our 30fps v-sync'd performance.
There are some very interesting constraints in GPU-programming. Fitting C++ classes and even some data-structures in the "shared memory" region is pretty nifty.
Looking at their example:
_Generic void prepend(_Forall(node_t)** head,
_Forall(value_t) value)
{
node_t* n = malloc(sizeof(node_t));
n->value = value;
n->next = *head;
*head = n;
}
For each use of `prepend()`, their frontend defines an appropriate struct with fields `value` then `next` (in that order) whose types are inferred from the assignments in the body of the function.Like what?