Zig

本页使用了标题或全文手工转换
维基百科,自由的百科全书
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是一個命令式通用静态型別编译的系統程式語言。 [3] [4]以「強健性、最佳性以及可維護性」為核心理念。[5] [6]它支援編譯時泛型與反射、交叉編譯以及手動記憶體管理。 [7]目標為改進 C语言[8] [9] ,同時參考從 Rust [10] [11]和其他語言。Zig 有許多低階程式設計的功能,例如緊緻結構(成員間沒有填充的結構)、任意大小的整數[12]以及多指針型別。[13]

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). 

外部連接