Skip to content

Commit

Permalink
更新小部分
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Oct 1, 2023
1 parent 60a0f49 commit 04f111c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
16 changes: 8 additions & 8 deletions learn/basic/advanced_type/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ outline: deep

::: code-group

```zig [结构体]
```zig [default]
const Circle = struct {
radius: u8,
Expand All @@ -38,7 +38,7 @@ const Circle = struct {
};
```

```zig [完整示例]
```zig [more]
const std = @import("std");
const Circle = struct {
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn main() void {

::: code-group

```zig [结构体]
```zig [default]
const User = struct {
userName: []u8,
password: []u8,
Expand Down Expand Up @@ -112,7 +112,7 @@ const User = struct {
};
```

```zig [完整示例]
```zig [more]
const std = @import("std");
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand Down Expand Up @@ -260,13 +260,13 @@ const x = Foo{

::: code-group

```zig [结构体]
```zig [default]
const Empty = struct {
// const PI = 3.14;
};
```

```zig [完整示例]
```zig [more]
const std = @import("std");
const Empty = struct {
Expand Down Expand Up @@ -468,7 +468,7 @@ test "overaligned pointer to packed struct" {

::: code-group

```zig [源代码]
```zig [default]
const std = @import("std");
pub fn main() void {
Expand All @@ -485,7 +485,7 @@ fn List(comptime T: type) type {
}
```

```sh [输出]
```sh [output]
variable: struct_name.main.Foo
anonymous: struct_name.main__struct_3509
function: struct_name.List(i32)
Expand Down
4 changes: 2 additions & 2 deletions learn/basic/process_control/decision.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ zig 中的三元表达式是通过 `if else` 来实现的:

::: code-group

```zig [简略]
```zig [default]
const a: u32 = 5;
const b: u32 = 4;
const result = if (a != b) 47 else 3089;
```

```zig [完整]
```zig [more]
const print = @import("std").debug.print;
pub fn main() !void {
Expand Down
6 changes: 5 additions & 1 deletion learn/basic/process_control/loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ outline: deep

<!-- 讲解标签 blocks break -->

TODO
在 zig 中,循环分为两种,一种是 `while`,一种是 `for`

## `while`

## `for`
36 changes: 35 additions & 1 deletion learn/basic/union.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,38 @@ outline: deep

# 联合类型

TODO
联合类型(union),它实际上用户定义的一种特殊的类型,划分出一块内存空间用来存储多种类型,但同一时间只能存储一个类型。

联合类型的基本使用:

::: code-group

```zig [default]
const Payload = union {
int: i64,
float: f64,
boolean: bool,
};
var payload = Payload{ .int = 1234 };
print("{}\n",.{payload.int});
```


```zig [more]
const print = @import("std").debug.print;
const Payload = union {
int: i64,
float: f64,
boolean: bool,
};
pub fn main() !void {
var payload = Payload{ .int = 1234 };
print("{}\n", .{payload.int});
}
```
:::

0 comments on commit 04f111c

Please sign in to comment.