5 ms·
To whom?
by mauricioc 4y ago
To whom?
- Alifatisk 4y agoTo me, for example. > .{}
- deleted 4y ago[deleted]
- brabel 4y agoIs C foreign to you? Zig syntax is nearly identical to how C initializes structs.
- mauricioc 4y agoFor 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 https://github.com/ziglang/zig/issues/5039.
- kristoff_it 4y agoThat'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.
- jussij 4y agoThe 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, });
- fancl20 4y agoIt's not invented by zig: https://en.cppreference.com/w/c/language/struct_initialization https://en.cppreference.com/w/c/language/struct_initializati... Although more widely used.