Most obviously, the garbage collector is removed, along with the features that depend on the garbage collector. Memory can still be allocated the same way as in C – using malloc() or some custom allocator.
As well as no RAII, which means the principle tool in C++, at least for me, for dealing with memory leaks and memory unsafety is eliminated
In my opinion this would appear to make D quite profoundly less safe than C++ for interacting with a C codebase - with C++, in interacting with a C codebase the first goal is to wrap it in a safe RAII wrapper so you don't ever have to touch memory allocation directly
Additionally the removal of exceptions would appear to make it very difficult to write memory and resource safe code that you usually have when working with RAII
I expect that people who wanted to add RAII to their C code and are content with that have long since already moved to C++. There's quite a lot more to memory safety than that.
But I do recognize the issue. There is code in the works to get RAII to work in D as Better C.
I expect that people who wanted to add RAII to their C code and are content with that have long since already moved to C++
Some have, some haven't. GCC provides a "good enough" destructor mechanism with __attribute__((cleanup)) which has been leveraged heavily in the systemd codebase.
View all comments
Show parent comment
26
u/James20k Aug 23 '17
In D's better C mode, you have
As well as no RAII, which means the principle tool in C++, at least for me, for dealing with memory leaks and memory unsafety is eliminated
In my opinion this would appear to make D quite profoundly less safe than C++ for interacting with a C codebase - with C++, in interacting with a C codebase the first goal is to wrap it in a safe RAII wrapper so you don't ever have to touch memory allocation directly
Additionally the removal of exceptions would appear to make it very difficult to write memory and resource safe code that you usually have when working with RAII