90 points · by unusualcool · 7y ago · 70 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.
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?
One of the reasons I'm actually going for pure C in this modern day and age, is that I can just write a small program, without having any other dependency.
I'm sure the same could be said for C++, too, but for some reason, with my setup (GCC 5.1.0 with MinGW on Windows 7), I'm averaging around 800KB on C++ vs 80KB on C, for the (mostly) same code. EDIT: It appears that exception-handling is one of the reasons the binary is bigger in C++ than C.
I mainly write code for embedded devices, so whatever programs I write on x86 is to interface with those devices, hence I'm quite comfortable staying with C.
I'm in the same situation and I use C# for windows based tools.
Is this considered harmful because it hides the fact that you're dealing with a pointer in the first place?
If you apply qualifiers like const to your type, results might me unexpected.
It might have semantic benefits, but C developers should be trained to ignore all these strange *-symbols anyway.
While I've great respect for the authors of that fantastic library, I only have this to say about the practice: Jeeesh!
It's all semantic sugar anyway.
I typedef function pointers when they get too verbose. Otherwise not. But it's not the mole hill I'd choose to die on either.
[1]: http://www.robertgamble.net/2012/01/c11-generic-selections.h...
[1] https://ziglang.org/download/0.1.1/release-notes.html [2] https://andrewkelley.me/post/intro-to-zig.html
* [0.2.0 release notes](https://ziglang.org/download/0.2.0/release-notes.html)
* [0.3.0 release notes](https://ziglang.org/download/0.3.0/release-notes.html)
* [0.4.0 release notes](https://ziglang.org/download/0.4.0/release-notes.html)
0.5.0 is scheduled to be released Sept 30.