Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig: Pro #377

Open
hhstore opened this issue Aug 13, 2022 · 5 comments
Open

Zig: Pro #377

hhstore opened this issue Aug 13, 2022 · 5 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Aug 13, 2022

related:

@hhstore
Copy link
Owner Author

hhstore commented Aug 13, 2022

Zig 进阶:

  • zig 总体上比 rust 语法简单很多.
  • 和 c 相比, 并没有引入太多难理解的概念. (一致性上近似 c)

官方文档:

zig 语法关键字:

zig 语法练习:

@hhstore
Copy link
Owner Author

hhstore commented Aug 13, 2022

Zig 核心语法点:

💢 1. 数据类型:

基础数据类型:

Optionals: (类似 Rust Option)

null:

undefined:

Arrays: 数组

Vectors: 容器

Slices: 切片

struct: 结构体

extern-struct:

Pointers: 指针

💢 2. 基本语法:

opaque: ⭐⭐⭐⭐⭐

blocks: 块语法, 类似 rust/go, {}, 生命周期概念.

noreturn:

💢 3. 进阶语法:

3.1 错误处理:

defer / errdefer:

try / catch: 异常机制

switch: 类似 rust match

unreachable:

3.2 comptime: 类似泛型

3.3 编译期反射和编译期代码执行:

3.4 异步(Async/Await):

3.5 C 语言互操作:

@hhstore
Copy link
Owner Author

hhstore commented Aug 13, 2022

Zig 语法进阶:

  • 重点介绍一些比较重要 or 不太清晰的特性.

type vs anytype:

anytype 用例:

comptime:

典型例子:

errors:

文档:

示例:

Builtin-Functions 内建方法集:

@hhstore
Copy link
Owner Author

hhstore commented Aug 13, 2022

1

1 similar comment
@hhstore
Copy link
Owner Author

hhstore commented Aug 13, 2022

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant