You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/zig-for-c-devs.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -689,6 +689,26 @@ switch (v) {
689
689
690
690
Tagged unions (which union you're using is tracked at runtime) are also supported.
691
691
692
+
## Dot based type inference
693
+
694
+
In zig a type can be inferred, but inference is explicitely denoted by a dot. The leading . is a shorthand literal/variant marker used when the target type can be inferred from context:
695
+
696
+
```zig
697
+
// zig
698
+
699
+
// arrays
700
+
const array1: [4]i32 = .[1, 2, 3, 4];
701
+
const array2: [4]i32 = [4]i32{1, 2, 3, 4};
702
+
703
+
// structs
704
+
const p1: Point = .{ .x = 10, .y = 20 };
705
+
const p2: Point = Point{ .x = 10, .y = 20 };
706
+
707
+
// enum values
708
+
const color1: Color = .Red;
709
+
const color2: Color = Color.Red;
710
+
```
711
+
692
712
## Enums
693
713
694
714
Zig has enums similar to C but with more features:
0 commit comments