3 ms·
what does zig offer over c/c++ with sanitizers?
by kobebrookskC3 5y ago
what does zig offer over c/c++ with sanitizers?
- dnautics 5y agoSanity. Seriously. You get these tests for free with zig, no extra tooling, if you use testing allocator in your tests. This also is a carrot to get you to write tests. Hell, I even mocked libc's malloc/calloc/free to make sure that my code doesn't leak memory: https://github.com/ityonemo/Primes/blob/ee81d05e80d68854ab1139b27e5607b65997fd80/PrimeZig/solution_3/src/alloc.zig#L175 https://github.com/ityonemo/Primes/blob/ee81d05e80d68854ab11...
- pjmlp 5y agoWhat sanity when the developer is still responsible for tracking memory manually by themselves? > It is the Zig programmer's responsibility to ensure that a pointer is not accessed when the memory pointed to is no longer available. https://ziglang.org/documentation/0.8.1/#Memory https://ziglang.org/documentation/0.8.1/#Memory Mocking malloc you say? https://docs.microsoft.com/en-us/visualstudio/debugger/crt-debug-heap-details?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/debugger/crt-d... It exists at very least since Visual C++ 5.0, and Borland had similar tooling since their first Win16 compilers.
- dnautics 5y agoRust does not free you from having to track memory, for large classes of important data structures. And, if you want to implement smart pointers for your app in zig, it is easy. Yes, your examples are two proprietary, nonstandard techniques. Or alternatively using a third-class toolset (jemalloc toolkit e.g ). Sanity is having a single, anointed way to do it in the stdlib.