Re:Adding Modules to C in 10 Lines of Code [pdf]
by OskarS on Monday June 27, 2022 @07:50AM
(#31893224)
> Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators)
If you do that, is it RAII like C++/Rust? Objects get destructed at end of scope, and members get destructed recursively? Or do you have to manually call `free()` on everything? (which, granted, is significantly easier in languages with `defer` mechanisms)
Re:Adding Modules to C in 10 Lines of Code [pdf]
by Shadonototra on Monday June 27, 2022 @04:38PM
(#31900471)
D has defer
scope(exit):
scope(failure):
scope(success):
https://tour.dlang.org/tour/en/gems/scope-guardsYou can do RAII with D too, it's your choice, based on your use case
Re:Adding Modules to C in 10 Lines of Code [pdf]
by WalterBright on Monday June 27, 2022 @02:20PM
(#31898509)
Yes, it is RAII and RAII is fully implemented in D.
Re:Adding Modules to C in 10 Lines of Code [pdf]
by alphaglosined on Monday June 27, 2022 @03:26PM
(#31899535)
But only for structs.
We really need to get actual reference counting into the language to cover classes properly as well.
It has been on my todo list to write a DIP for this for a while now. ~rikki.
GC only exist if you call ``new MyThing``
Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators)
if you want to enforce no GC use in your APIs, there is the @nogc attribute you can use