Re:Why Zig when there is already C++, D, and Rust?
by pasabagi on Saturday January 16, 2021 @05:21AM
(#25801356)
I found it very difficult to deal with C macros, though. That said, I have no idea how zig deals with that problem either.
[ Parent
| on HN ]
Re:Why Zig when there is already C++, D, and Rust?
by justincormack on Saturday January 16, 2021 @06:25AM
(#25801582)
Zig can handle C macros, you can see this if you use the zig translate-c option on the CLI which will convert any C code to Zig. This does make it the most usable C ffi I have used, as it means it really works with even difficult C code.
Re:Why Zig when there is already C++, D, and Rust?
by exyi on Saturday January 16, 2021 @05:27AM
(#25801376)
This seems like unsolvable problem - if you'd want to allow calling C macros from your new language, you would have to be C superset. So no memory/thread/... safety, weird syntax inherited from C, ...
Re:Why Zig when there is already C++, D, and Rust?
by skohan on Saturday January 16, 2021 @06:01AM
(#25801503)
This was one of the most redeeming things about Objective-C. It is a superset of C, and when I was working with it, I found myself writing the high-level stuff in ObjC, but with a lot of pure-C functions sprinkled in. It was really nice for working with C libraries like OpenGL, because you could find an example online and directly apply it without going through any kind of translation step. It was a really cool feature to have.
Re:Why Zig when there is already C++, D, and Rust?
by pjmlp on Saturday January 16, 2021 @04:09PM
(#25805534)
I share a similar experience with C++.
However that compatibility is also what makes Objective-C and C++ impossible to ever be fully safe, without breaking compatibility with the C subset.
Static analysis help, but only when all code is available.
Re:Why Zig when there is already C++, D, and Rust?
by beagle3 on Saturday January 16, 2021 @07:43AM
(#25801873)
It isn’t so black and white.
Nim, if you let it use C as a backend, will let you use C macros, despite being generally safe and not remotely a C superset.
Yes, the use of C macros (and any kind of ffi) is unsafe, that cannot be avoided. But it doesn’t need to be a c superset (and indeed, when you use JS as a backend, or the native LLVM backend, you get no access to C macros)