Skip to content

Commit 5e6fd8d

Browse files
committed
Update zig-for-c-devs.md
1 parent 8813940 commit 5e6fd8d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

content/posts/zig-for-c-devs.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,26 @@ switch (v) {
689689

690690
Tagged unions (which union you're using is tracked at runtime) are also supported.
691691

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+
692712
## Enums
693713

694714
Zig has enums similar to C but with more features:

0 commit comments

Comments
 (0)