3 ms·
Why did they keep the dot in Struct initialisation? Why not the syntax of just using without dot: const c1 = Config{ port = 8000, host = "127.0.0.1", };
by NoelJacob 2y ago
Why did they keep the dot in Struct initialisation? Why not the syntax of just using without dot:
const c1 = Config{
port = 8000,
host = "127.0.0.1",
};
Is there some other use with dotless one?
- throwawaymaths 2y agoBecause your type name might be std.foo.bar.baz.quux.Config
- thezipcreator 2y agoJust `{}` means a code block; in Zig you could do something like const c = blk: { const x = 5; break :blk x-3; }; // c = 2 just having an empty block `{}` is exactly that—an empty block of type `void`. having a dot or something else distinguishing it from a block is necessary in order for it to not be that.
- flohofwoe 2y agoIn many situations the compiler can infer the type: fn my_func(): MyType { return .{ ... }; } The dot is just the placeholder for the inferred type and the above is equivalent with: fn my_func(): MyType { return MyType{ ... }; } ...and Zig allows to write that verbose form too if you prefer that.