4 comments

  • tobias12345 a day ago ago

    How will porting a single concept like `defer` from zig, a language that is not memory safe, to C and C++ make those memory safe?

    `defer` is a poor man's RAII. C++ has had RAII since the beginning, and C++ is still not considered memory safe. So how will adding `defer` help C++ to become memory safe?

    This feels like another example of how poorly C and C++ devs understand the ideas behind memory safety. You do not really need to understand this concept, as long as you can debug all the memory issues that just pop up:-)

  • Panzerschrek 2 days ago ago

    How memory safety is implemented? Is it even possible with a simple preprocessor tool?

    • KrishnaTorque 2 days ago ago

      Right now there are 3 approaches. The "defer" will free memory when exit scope. Then there is a "try" macro which will handle IO. Then there is macro expansion which will ensure to compile safely. However there are a tons of things to do. It is still in alpha.

      • Panzerschrek a day ago ago

        I see no way "defer" may guarantee memory safety. And why is it needed at all in C++, where destructors do similar job of resources freeing?