Zig是一个命令式通用静态类型编译的系统编程语言。 [3] [4]以“强健性、最佳性以及可维护性”为核心理念。[5] [6]它支持编译时泛型与反射、交叉编译以及手动存储器管理。 [7]目标为改进 C语言[8] [9] ,同时参考从 Rust [10] [11]和其他语言。Zig 有许多低端程式设计的功能,例如紧致结构(成员间没有填充的结构)、任意大小的整数[12]以及多指针类型。[13]

Zig
编程范型多重编程范型: 命令式, 并发, 过程式, 函数
设计者Andrew Kelley
发行时间2016年2月8日,​8年前​(2016-02-08[1]
当前版本
  • 0.12.0 (2024年4月20日)[2]
编辑维基数据链接
类型系统静态, , 自动推导, 结构化, 泛型
系统平台x86-64, ARM, MIPS, IA-32, WebAssembly, RISC-V
操作系统跨平台
许可证MIT许可证
文件扩展名.zig, .zir
网站ziglang.org
启发语言
C语言, C++, LLVM IR, Go, Rust, JavaScript

Zig 最初的编译器是用 Zig 和 C++ 编写而成,以 LLVM 13[14] 为后端[15] [16]。这个编译器使用 MIT许可证 授权。Zig 编译器和 Clang 类似,能编译 C 与 C++(使用“zig cc”以及“zig c++”指令)[17],也为不同的平台提供头文件,包括 C标准函式库C++标准函式库,因此 Zig 的 cc 与 c++ 子命令能直接作为交叉编译器[18] [19]

Zig 的开发由 Zig 软件基金会 (ZSF) 资助,该资金会是一家非营利公司,由 Andrew Kelley 担任总裁,也有雇佣一些全职员工,同时接受捐款。 [20] [21] [22]

示例

Hello World

const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, {s}!\n", .{"World!"});
}

链表

pub fn main() void {
    var node = LinkedList(i32).Node {
        .prev = null,
        .next = null,
        .data = 1234,
    };

    var list = LinkedList(i32) {
        .first = &node,
        .last = &node,
        .len = 1,
    };
}

fn LinkedList(comptime T: type) type {
    return struct {
        pub const Node = struct {
            prev: ?*Node,
            next: ?*Node,
            data: T,
        };

        first: ?*Node,
        last:  ?*Node,
        len:   usize,
    };
}

参见

参考资料

  1. ^ Kelley, Andrew. Introduction to the Zig Programming Language. andrewkelley.me. [8 November 2020]. (原始内容存档于2022-02-21). 
  2. ^ 2.0 2.1 Release 0.12.0. 
  3. ^ Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot. JAXenter. 2017-10-31 [2020-02-11]. (原始内容存档于2021-11-25) (美国英语). 
  4. ^ Tired of C? New programming language Zig aims to be more pragmatic and readable. 2017-10-19 [2020-04-22]. (原始内容存档于2021-11-25) (美国英语). 
  5. ^ Yegulalp, Serdar. New challenger joins Rust to topple C language. InfoWorld. 2016-08-29 [2020-02-11]. (原始内容存档于2021-11-25) (英语). 
  6. ^ Zig language and C. Sina Corp. 2020-07-12 [2020-08-12]. (原始内容存档于2021-11-25). 
  7. ^ The Zig Programming Language. ziglang.org. [2020-02-11]. (原始内容存档于2022-04-01). 
  8. ^ Mozilla's Observatory, the Zig programming language, and uSens' VR/AR SDK—SD Times news digest: Aug. 29, 2016. SD Times. 2016-08-29 [2020-02-11]. (原始内容存档于2021-11-25) (美国英语). 
  9. ^ The Zig Programming Language. ziglang.org. [2020-02-11]. (原始内容存档于2022-04-01). 
  10. ^ Company, Sudo Null. Sudo Null - IT News for you. SudoNull. [2020-02-11]. (原始内容存档于2021-11-25) (英语). 
  11. ^ Kelley, Andrew. Unsafe Zig is Safer Than Unsafe Rust. andrewkelley.me. [2020-02-11]. (原始内容存档于2022-02-21). 
  12. ^ Tim Anderson 24 Apr 2020 at 09:50. Keen to go _ExtInt? LLVM Clang compiler adds support for custom width integers. www.theregister.co.uk. [2020-04-24]. (原始内容存档于2020-05-15) (英语). 
  13. ^ Documentation - The Zig Programming Language. ziglang.org. [2020-04-24]. (原始内容存档于2022-03-31). 
  14. ^ SD Times news digest: C++20 concepts in Visual Studio 2010 version 16.3, Bootstrap to drop IE support, and Zig 0.60 released. SD Times. 2020-04-14 [2020-04-19]. (原始内容存档于2021-11-25) (美国英语). 
  15. ^ A Reply to _The Road to Zig 1.0_. www.gingerbill.org. 2019-05-13 [2020-02-11]. (原始内容存档于2021-09-07) (英国英语). 
  16. ^ ziglang/zig, Zig Programming Language, 2020-02-11 [2020-02-11], (原始内容存档于2022-03-30) 
  17. ^ 0.6.0 Release Notes · The Zig Programming Language. ziglang.org. [2020-04-19]. (原始内容存档于2022-02-21). 
  18. ^ 'zig cc': a Powerful Drop-In Replacement for GCC/Clang - Andrew Kelley. andrewkelley.me. [2021-05-28]. (原始内容存档于2022-03-17). 
  19. ^ Zig Makes Go Cross Compilation Just Work. DEV Community. [2021-05-28]. (原始内容存档于2022-03-03) (英语). 
  20. ^ Jakub Konka on Twitter. Twitter. [2021-05-28]. (原始内容存档于2021-12-01) (英语). 
  21. ^ Announcing the Zig Software Foundation ⚡ Zig Programming Language. ziglang.org. [2021-05-28]. (原始内容存档于2021-11-15). 
  22. ^ Sponsor ZSF ⚡ Zig Programming Language. ziglang.org. [2021-05-28]. (原始内容存档于2022-02-21). 

外部连接