Example from the article:
const win32 = @cImport({
@cInclude("windows.h");
@cInclude("winuser.h");
});
pub fn main() !void {
_ = win32.MessageBoxA(null, "world!", "Hello", 0);
}
Equivalent D: import windows, winuser;
void main() {
MessageBoxA(null, "world!", "Hello", 0);
}
In essence pared it down to the essentials. The compiler figures out the rest.Sometimes people ask for a special syntax for importing C files, but I like this simplicity so much better.
I really want to like zig, but I've just had some annoying problems with it, most of which I think are just a result of it not being in 1.0 yet. For example, the recommended way to start a project, with `zig init`, has a load of code that I really don't need when I just want a bare project to get started. I only recently found out that you can just `zig build-exe filename.zig` and skip the whole init part. Also I've had a lot of issues getting editor integration to work correctly. I've installed the VSCode extension but I don't seem to be getting autocomplete etc. It is quite possibly just an ID-10T problem though, so I'll probably take another look at it some weekend
Clang's preprocessor is actually not implemented as a separate compilation pre-pass, it's essentially a part of the lexer and I would be willing to bet that gcc uses a similar scheme.
So there is nothing technically impossible about having the access to macro names as a compiler-specific extension, it's just that there is no much demand for it.
Those function definitions really look amazingly readable. I've seen this done before in other languages and its usually quite horrible. Maybe Zig is worth learning? This is a killer feature.
I wrote a blogpost showing how you could do a similar thing in D with ImportC.
Wouldn’t this add at least UINT16_MAX*sizeof(intptr_t) bytes into the executable per enum?
Thank Apple for Reader View in Safari. If you are as incompetent in visual design as the author of that page, you should really stay away from dark mode. Your readers will thank you.
i like your site! seems like zig is really taking off.
@cImport is on the chopping block though [0]. You will still be able to import c files but it will require a little more work. This is because they want this functionality out of the language so they can remove libclang dependency.
[0]: https://github.com/ziglang/zig/issues/20630