Jump to content

Zig (programming language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Added archive links, since the original links to jaxenter.com don't seem to go to the right place anymore
Ef3 (talk | contribs)
→‎Hello World: Fix to ver. 0.9.1
Line 32: Line 32:
pub fn main() !void {
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {}!\n", .{"world"});
try stdout.print("Hello, {s}!\n", .{"world"});
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 05:02, 26 September 2022

Zig
ParadigmsMulti-paradigm: imperative, concurrent, procedural, functional
Designed byAndrew Kelley
First appeared8 February 2016; 8 years ago (2016-02-08)[1]
Preview release
0.13.0[2] Edit this on Wikidata / 6 June 2024; 3 months ago (6 June 2024)
Typing disciplineStatic, strong, inferred, structural, generic
Platformx86-64, ARM, MIPS, IA-32, WebAssembly, RISC-V
OSCross-platform
LicenseMIT License
Filename extensions.zig, .zir
Websiteziglang.org
Influenced by
C, C++, LLVM IR, Go, Rust, JavaScript

Zig is an imperative, general-purpose, statically typed, compiled system programming language designed by Andrew Kelley.[3][4] The language is designed for "robustness, optimality and maintainability",[5][6] supporting compile-time generics, reflection and evaluation, cross-compilation and manual memory management.[7] A major goal of the language is to improve upon the C language,[8][9] while also taking inspiration from Rust,[10][11] among others. Zig has many features for low-level programming, notably packed structs (structs without padding between fields), arbitrary width integers[12] and multiple pointer types.[13]

The stage 1 compiler is written in Zig and C++, using LLVM 13[14] as a back-end,[15][16] supporting many of its native targets.[17] The compiler is open source under the MIT License.[18] The Zig compiler exposes the ability to compile C and C++ similarly to Clang with the commands "zig cc" and "zig c++",[19] providing many headers including libc and libcxx for many different platforms, allowing Zig's cc and c++ sub-commands to act as cross compilers out of the box.[20][21]

Zig development is funded by the Zig Software Foundation (ZSF), a non-profit corporation with Andrew Kelley as president, which takes in donations and hires multiple full-time employees.[22][23][24]

Examples

Hello World

const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
}

Generic linked list

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,
    };
}

See also

References

  1. ^ Kelley, Andrew. "Introduction to the Zig Programming Language". andrewkelley.me. Retrieved 8 November 2020.
  2. ^ "Release 0.13.0".
  3. ^ "Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot". JAXenter. 2017-10-31. Archived from the original on 2017-11-01. Retrieved 2020-02-11.
  4. ^ "Tired of C? New programming language Zig aims to be more pragmatic and readable". 2017-10-19. Archived from the original on 2020-10-01. Retrieved 2020-04-22.
  5. ^ Yegulalp, Serdar (2016-08-29). "New challenger joins Rust to topple C language". InfoWorld. Retrieved 2020-02-11.
  6. ^ "Zig language and C". Sina Corp. 2020-07-12. Retrieved 2020-08-12.
  7. ^ "The Zig Programming Language". ziglang.org. Retrieved 2020-02-11.
  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. Retrieved 2020-02-11.
  9. ^ "The Zig Programming Language". ziglang.org. Retrieved 2020-02-11.
  10. ^ Company, Sudo Null. "Sudo Null - IT News for you". SudoNull. Retrieved 2020-02-11. {{cite web}}: |last= has generic name (help)
  11. ^ Kelley, Andrew. "Unsafe Zig is Safer Than Unsafe Rust". andrewkelley.me. Retrieved 2020-02-11.
  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. Retrieved 2020-04-24.{{cite web}}: CS1 maint: numeric names: authors list (link)
  13. ^ "Documentation - The Zig Programming Language". ziglang.org. Retrieved 2020-04-24.
  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. Retrieved 2020-04-19.
  15. ^ "A Reply to _The Road to Zig 1.0_". www.gingerbill.org. 2019-05-13. Retrieved 2020-02-11.
  16. ^ ziglang/zig, Zig Programming Language, 2020-02-11, retrieved 2020-02-11
  17. ^ "The Zig Programming Language". ziglang.org. Retrieved 2020-02-11.
  18. ^ "ziglang/zig". GitHub. Retrieved 2020-02-11.
  19. ^ "0.6.0 Release Notes · The Zig Programming Language". ziglang.org. Retrieved 2020-04-19.
  20. ^ "'zig cc': a Powerful Drop-In Replacement for GCC/Clang - Andrew Kelley". andrewkelley.me. Retrieved 2021-05-28.
  21. ^ "Zig Makes Go Cross Compilation Just Work". DEV Community. Retrieved 2021-05-28.
  22. ^ "Jakub Konka on Twitter". Twitter. Retrieved 2021-05-28.{{cite web}}: CS1 maint: url-status (link)
  23. ^ "Announcing the Zig Software Foundation ⚡ Zig Programming Language". ziglang.org. Retrieved 2021-05-28.
  24. ^ "Sponsor ZSF ⚡ Zig Programming Language". ziglang.org. Retrieved 2021-05-28.