Welcome to EverybodyWiki ! Nuvola apps kgpg.png Sign in or create an account to improve, watchlist or create an article like a company page or a bio (yours ?)...

Zig Programming Language

From EverybodyWiki Bios & Wiki
Jump to navigation Jump to search








Zig
Logo for the Zig programming language
Paradigmimperative, compiled, procedural
Designed byAndrew Kelley
First appeared2015; 4 years ago (2015)
Stable release
0.3.0 / September 28, 2018; 10 months ago (2018-09-28)[1]
Typing disciplinestatic
Platformi386, x86-64, arm, aarch64, bpf, hexagon, mips, powerpc, r600, amdgcn, sparc, s390x, thumb, spir, lanal
OSCross-platform[2][3]
LicenseMIT[4]
Filename extensions.zig
Websiteziglang.org
Influenced by
C, C++, Go

Zig is an open-source programming language designed for "robustness, optimality, and clarity".[3][5][6] The language is intended to compete directly with C and libc is not a dependency, although you can still directly import C header files.[5][7][6] The founder and main designer of Zig is Andrew Kelley.[6]

Language Design[edit | edit source]

Specific inspirations for Zig's design include the following:

  • C: Strict outlook on language features
  • Rust: Avoiding null types
  • Go: Defer
  • Jai: Allocators, compile-time function evaluation
  • Node.js: @import, async, and await
  • LLVM IR: Builtins

The syntax takes cues from C, Rust, and Go. Zig is designed with thorough safety in mind, and as such manual memory management is critical feature, holding the principal that "edge cases matter."[7][8] Zig purposefully discards C's preprocessor, instead focusing on other compile-time code possibilities. The language is designed to make cross-compilation easy.[5] Zig utilizes LLVM currently.[9]

The standard library has been influenced by musl, libc, and wine.

Examples[edit | edit source]

Hello World[edit | edit source]

const debug = @import("std").debug;

pub fn main() void {
    debug.warn("Hello, world!\n");
}

Importing C Header Files[edit | edit source]

const c = @cImport({
    @cInclude("stdio.h");
});

Enumerations[edit | edit source]

const CatBreed = enum {
    Siamese,
    Bengal,
    Shorthair,
    Other,
};

You can also clarify the integers associated with each name.

const CatBreed = enum(u8) {
    Siamese = 0,
    Bengal = 1,
    Shorthair = 5,
    Other = 10,
};

Factorial[edit | edit source]

The code below is an implementation of the factorial function in Zig. Marking a parameter with comptime indicates that the value must be known at compile-time, something that Zig places importance on.[10]

const std = @import("std");

pub fn factorial(comptime n: comptime_int) comptime_int {
    return if (n > 0) n * factorial(n - 1) else 1;
}

pub fn main() void {
    std.debug.warn("{}\n", u128(factorial(30)));
}

References[edit | edit source]

  1. "GitHub Releases". Github.com. Retrieved 2018-11-12.
  2. "GitHub Readme". Github.com. Retrieved 2018-11-12.
  3. 3.0 3.1 Elizabeth, Jane (2017-10-19). "New programming language Zig aims to be more pragmatic and readable". Jaxenter.com. Retrieved 2018-11-12.
  4. "GitHub License File". Github.com. Retrieved 2018-11-12.
  5. 5.0 5.1 5.2 Cardoza, Christina; Moore, Madison (2016-08-29). "SD Times news digest". Sdtimes.com. Retrieved 2018-11-12.
  6. 6.0 6.1 6.2 Yegulalp, Serdar (2016-08-29). "New challenger joins Rust to topple C language". Infoworld.com. Retrieved 2018-11-12.
  7. 7.0 7.1 "Ziglang Website". Ziglang.org. Retrieved 2018-11-12.
  8. "Recurse Center Presentation". Recurse.com. Retrieved 2018-11-12.
  9. "LLVM Weekly News". LLVMweekly.org. Retrieved 2018-11-19.
  10. "Ziglang Documentation". Ziglang.org. Retrieved 2018-11-12.

External links[edit | edit source]

Category:Programming languages Category:Concurrent programming languages Category:Statically typed programming languages Category:Systems programming languages Category:Multi-paradigm programming languages Category:Procedural programming languages Category:Software using the MIT license Category:Cross-platform software Category:Free compilers and interpreters


This article "Zig Programming Language" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Zig Programming Language. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.


Compte Twitter EverybodyWiki Follow us on https://twitter.com/EverybodyWiki !