back
5 comments
That's the same as using `{}` in C to initialize a struct. The dot only makes more clear that it's a struct literal and not a scope.
The language cetainly seems to like using that 'dot' operator:

    const exe = b.addExecutable(.{
        .name = "demo",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
It's not invented by zig: https://en.cppreference.com/w/c/language/struct_initializati...

Although more widely used.

For the example you cited (anonymous struct literals), there are two parts to it:

1) It omits the constructor name. My uneducated guess is that "modern" languages try to avoid the Java-style pattern of repeating a type/constructor many times in a single line (e.g., "Point pt = new Point(0, 0)") when it can infer things to help the developer.

2) It starts with a dot, while C++'s compound literals (for example) don't. The pros and cons of this are discussed in https://github.com/ziglang/zig/issues/5039.

Is C foreign to you? Zig syntax is nearly identical to how C initializes structs.