Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> So Zig is as expressive as C++. but not only safer, but also much simpler, and compiles faster

Tbh syntax-wise Zig feels more cryptic[1] at first than C++.

[1] e.g. `extern "user32" fn MessageBoxA(?win.HWND, [*:0]const u8, [*:0]const u8, u32) callconv(win.WINAPI) i32;` from https://ziglang.org/learn/samples/



I think that's just a matter of syntax habits, presumably because you're already familiar with C++ syntax. The syntax in your example is especially "cryptic" simply because it's an FFI signature (of a function that's not written in Zig and doesn't use the normal Zig data representations).


To be clear the equivalent C++ code is:

    #include <windows.h>
    extern "C" __declspec(dllimport) int __stdcall MessageBoxA(HWND, LPCSTR, LPCSTR, UINT);
    // or
    extern "C" __declspec(dllimport) int __stdcall MessageBoxA(void *, const char[], const char[], unsigned int);
It's not exactly a stellar improvement.


Lol, no this is the equivalent

  #include <windows.h>

 int main() {
      MessageBoxA(NULL, "world!", "Hello", 0);
      return 0;
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: