Zig (programming language): Difference between revisions

Content deleted Content added
Projects: fix spacing
No edit summary
Line 21:
<ref>{{cite web | url=https://ziglang.org/learn/why_zig_rust_d_cpp/ | title=Why Zig when There is Already C++, D, and Rust? ⚡ Zig Programming Language }}</ref>
<ref>{{cite web | url=https://stackoverflow.blog/2023/10/02/no-surprises-on-any-system-q-and-a-with-loris-cro-of-zig/ | title=No surprises on any system: Q&A with Loris Cro of Zig - Stack Overflow | date=2 October 2023 }}</ref>
<ref>{{cite web | url=https://news.ycombinator.com/item?id=24615916 | title=Zig'sZig’s New Relationship with LLVM &#124; Hacker News }}</ref>
<ref>{{cite web | url=https://www.reddit.com/r/rust/comments/14zehei/zig_moving_away_from_llvm_and_llvm_ecosystem/ | title=Zig moving away from LLVM and LLVM ecosystem | date=14 July 2023 }}</ref>
<ref>{{cite web | url=https://www.youtube.com/watch?v=5_oqWE9otaE | title=What'sWhat’s Zig got that C, Rust and Go don'tdon’t have? (With Loris Cro) | website=[[YouTube]] | date=15 November 2023 }}</ref>
<ref>https://news.ycombinator.com/item?id=25797025</ref>
<ref>{{cite web | url=https://ziglang.org/learn/overview/ | title=Overview ⚡ Zig Programming Language }}</ref>
Line 30:
'''Zig''' (Also known as Ziglang)<ref>{{Cite web |title=Home ⚡ Zig Programming Language |url=https://ziglang.org/ |access-date=2024-12-31 |website=ziglang.org}}</ref> is an [[Imperative programming|imperative]], [[General-purpose programming language|general-purpose]], [[statically typed]], [[Compiled language|compiled]] [[System programming language|system]] [[programming language]] designed by Andrew Kelley.<ref>{{Cite web |date=2021-10-19 |title=Taking the warts off C, with Andrew Kelley, creator of the Zig programming language |url=https://sourcegraph.com/podcast/andrew-kelley |access-date=2024-04-18 |website=Sourcegraph |language=en}}</ref> It is intended as a successor to the language [[C (programming language)|C]], with the intent of being even smaller and simpler to program in, while offering more functionality.<ref>{{Cite web |date=2017-10-31 |title=Zig has all the elegant simplicity of C, minus all the ways to shoot yourself in the foot |url=https://jaxenter.com/zig-language-kelley-interview-138517.html |archive-url=https://web.archive.org/web/20171101231710/https://jaxenter.com/zig-language-kelley-interview-138517.html |archive-date=2017-11-01 |access-date=2020-02-11 |website=JAXenter |language=en-US}}</ref> It is [[free and open-source software]], released under an [[MIT License]].
 
The improvements in language simplicity relate to flow control, [[Function (computer programming)|function calls]], [[Library (computing)|library]] imports, [[Declaration (computer programming)|variable declaration]] and [[Unicode]] support. Further, the language makes no use of [[Macro (computer science)|macros]] or [[preprocessor]] instructions. Features adopted from modern languages include the addition of [[compile time]] [[generic programming]] [[data type]]s, allowing functions to work on a variety of data, along with a small set of new [[compiler]] directives to allow access to the information about those types using [[reflective programming]] (reflection).<ref name=zig>{{Cite web|url=https://ziglang.org/|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref>
 
Another set of additions to Zig is intended to improve code safety. A major goal of the language is to improve on the [[C (programming language)|C language]],<ref name="roadtozig1.0" /><ref>{{Cite web|url=https://ziglang.org/#Zig-competes-with-C-instead-of-depending-on-it|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref> while also taking inspiration from [[Rust (programming language)|Rust]],<ref>{{Cite web |title=Zig programming language |url=https://sudonull.com/post/3683-Zig-programming-language |access-date=2020-02-11 |website=SudoNull |language=en}}</ref>{{sfn|Yegulalp|2016}} among others. Like C, Zig omits [[Garbage collection (computer science)|garbage collection]], and has [[manual memory management]].<ref isname=zig manual./> To help eliminate the potential errors that arise in such systems, it includes [[option type]]s, a simple [[Syntax (programming languages)|syntax]] for using them, and a [[unit testing]] framework built into the language. Zig has many features for [[Low-level programming language|low-level programming]], notably packed structs (structs without padding between fields), arbitrary-width integers<ref>{{Cite web |url=https://www.theregister.co.uk/2020/04/24/llvm_project_adds_support_for/ |title=Keen to go _ExtInt? LLVM Clang compiler adds support for custom width integers |last1=Anderson |first1=Tim |date=2020-04-24 |website=www.theregister.co.uk |language=en |access-date=2024-12-30}}</ref> and multiple pointer types.<ref name="zigdocumentation">{{Cite web|url=https://ziglang.org/documentation/master/|title=Documentation|website=Ziglang.org|access-date=2020-04-24}}</ref>
 
ZigThe hasmain adrawback fewof drawbacks.the If memorysystem is notthat, properlyalthough deallocatedZig has a growing community, as of 2024, it canremains resulta innew memorylanguage leakswith dueareas tofor theimprovement lackin ofmaturity, hiddenecosystem controland tooling.<ref name="logrocket">{{cite web |last=Chigozie |first=Oduah |title=Comparing Rust vs. Zig: Performance, Safety, and More |url=https://blog.logrocket.com/comparing-rust-vs-zig-performance-safety-more/ |website=LogRocket Blog |date=2024-06-04 |access-date=2024-07-16}}</ref> TheAlso the learning curve for Zig can be steep, especially for those unfamiliar with low-level programming concepts.<ref name="logrocket"/> The Althoughavailability Zigof haslearning aresources growingis community,limited asfor ofcomplex 2024use cases, itthough remainsthis ais newgradually languageimproving withas areasinterest forand improvementadoption in maturity, ecosystem and toolingincrease.<ref name="logrocket"/> InteroperabilityOther withchallenges othermentioned languagesby maythe posereviewers challenges,are asinteroperability itwith oftenother requireslanguages (extra effort to manage data marshaling and communication.<ref name="logrocket"/>is Finallyrequired), theas availabilitywell ofas learningmanual resourcesmemory isdeallocation limited(disregarding forproper complexmemory usemanagement cases,results thoughdirectly thisin ismemory gradually improving as interest and adoption increaseleaks).<ref name="logrocket"/>
==Description==
 
Zig development is funded by the Zig Software Foundation (ZSF), a non-profit corporation with Andrew Kelley as president, which accepts donations and hires multiple full-time employees.<ref>{{Cite web |title=Jakub Konka on Twitter |url=https://twitter.com/kubkon/status/1377146321136537602 |archive-url=https://web.archive.org/web/20220410102319/https://twitter.com/kubkon/status/1377146321136537602 |archive-date=2022-04-10 |access-date=2021-05-28 |website=Twitter |language=en}}</ref><ref>{{Cite web|title=Announcing the Zig Software Foundation|url=https://ziglang.org/news/announcing-zig-software-foundation/|access-date=2021-05-28|website=Ziglang.org}}</ref><ref>{{Cite web|title=Sponsor ZSF|url=https://ziglang.org/zsf/|access-date=2021-05-28|website=Ziglang.org}}</ref>
 
==Language==
===Goals===
The primary goal of Zig is to be a better solution to the sorts of tasks that are currently solved with C. A primary concern in that respect is readability; Zig attempts to use existing concepts and syntax wherever possible, avoiding the addition of different syntax for similar concepts. Further, it is designed for "robustness, optimality and maintainability", including a variety of features to improve safety, optimization, and testing. The small and simple syntax is an important part of the maintenance, as it is a goal of the language to allow maintainers to debug the code without having to learn the intricacies of a language they might not be familiar with.{{sfn|Elizabeth|2017}} Even with these changes, Zig can compile into and against existing C code; C headers can be included in a Zig project and their functions called, and Zig code can be linked into C projects by including the compiler-built headers.{{sfn|Yegulalp|2016}}
 
In keeping with the overall design philosophy of making the code simple and easy to read, the Zig system as a whole also encompasses a number of stylistic changes compared to C and other C-like languages. For instance, the [[Rust (programming language)|Rust]] language has [[operator overloading]] which means a statement like {{code|a {{=}} b + c}} might actually be a function call to a type'stype’s overloaded version of the plus operator. Further, that function might panic which might pre-empt any following code. In Zig, if something calls a function, it looks like a function call; if it doesn'tdoesn’t, it doesn'tdoesn’t look like a function call. If it raises an error, it is explicit in the syntax,{{sfn|Yegulalp|2016}} error handling is handled through error types and can be handled with catch or try.
 
The goals of Zig are in contrast to those of many other languages designed in the same time period, like [[Go (programming language)|Go]], [[Rust (programming language)|Rust]], [[Carbon (programming language)|Carbon]], and [[Nim (programming language)|Nim]]. Generally, these languages are more complex with added features like [[operator overloading]], functions that masquerade as values (properties), and many other features intended to aid in building large programs. These sorts of features have more in common with C++'s’s approach, and these languages are more along the lines of that language.{{sfn|Yegulalp|2016}} Zig has a more conservative extension of the type system, supporting compile time generics and accommodating a form of [[duck typing]] with the {{code|comptime}} directive.
 
===Memory handling===
Line 61 ⟶ 65:
</syntaxhighlight>
 
In this code, the {{code|allocator}} variable is passed a struct that describes what code should perform the allocation, and the {{code|repeat}} function returns either the resulting string or, using the optional type as indicated by the {{code|!}}, an Allocator.Error. By directly expressing the allocator as an input, memory allocation is never "hidden" within another function, it is always exposed to the API by the function that is ultimately calling for the memory to be allocated. No allocations are performed inside Zig'sZig’s [[standard library]]. Further, as the struct can point to anything, one can use alternative allocators, even ones written in the program. This can allow, for instance, small-object allocators that do not use the [[operating system]] functions that normally allocate an entire [[memory page]].<ref name=zigo>{{cite web |url=https://ziglearn.org/chapter-2/ |title=Allocators|date=11 September 2023 }}</ref>
 
Optional types are an example of a language feature that offers general functionality while still being simple and generic. They do not have to be used to solve null pointer problems, they are also useful for any type of value where "no value" is an appropriate answer. Consider a function {{code|countTheNumberOfUsers}} that returns an integer, and an integer variable, {{code|theCountedUsers}} that holds the result. In many languages, a [[Magic number (programming)|magic number]] would be placed in {{code|theCountedUsers}} to indicate that {{code|countTheNumberOfUsers}} has not yet been called, while many implementations would just set it to zero. In Zig, this could be implemented as an {{code|var theCountedUsers: ?i32 {{=}} null|lang=zig}} which sets the variable to a clear "not been called" value.<ref name=zigo/>
Line 82 ⟶ 86:
const c = @cImport(@cInclude("soundio/soundio.h"));
</syntaxhighlight>
The Zig code can now call functions in the soundio library as if they were native Zig code. As Zig uses new data types that are explicitly defined, unlike C'sC’s more generic {{code|int}} and {{code|float}}, a small number of directives are used to move data between the C and Zig types, including {{code|@intCast}} and {{code|@ptrCast}}.<ref name=zigo/>
 
===Cross compiling===
Zig treats cross-compiling as a first-class use-case of the language. This means any Zig compiler can compile runnable binaries for any of its target platforms, of which there are dozens. These include not only widely-used modern systems like [[ARM architecture family|ARM]] and [[x86-64]], but also [[PowerPC]], [[SPARC]], [[MIPS architecture|MIPS]], [[RISC-V]] and even the IBM [[z/Architecture]]s (S390). The toolchain can compile to any of these targets without installing additional software, all the needed support is in the basic system.<ref name=zigo/>
 
===Comptime===
Line 98 ⟶ 99:
This function takes in some type {{code|T}}, and returns a custom {{code|struct}} defining a linked list with that data type.
 
==Compiler==
===Origin of the name===
Zig is not just a new language: it also includes a C/C++ compiler, and can be used with either or both languages.<!-- "Zig competes with C instead of depending on it" -->
The name 'Zig' was reportedly chosen through a process involving a [[Python (programming language)|Python]] script that randomly combined letters, starting with the letter 'Z' and followed by a vowel or 'Y', in order to generate four-letter words. Despite the intended length, 'Zig', a three-letter word, was ultimately selected from the various combinations produced by the script.<ref>{{cite web |url=https://gist.github.com/andrewrk/73742bf4b8ed795c85ce |title=origin of the zig programming language name. by @andrewrk |author=andrewrk |date=2024-03-13 |access-date=2024-03-13}}</ref>
 
The older [[Bootstrapping (compilers)|bootstrapping]] ("stage1") compiler is written in Zig and [[C++]], using [[LLVM]] 13 as a back-end,<ref>{{Cite web|url=https://www.gingerbill.org/article/2019/05/13/a-reply-to-the-road-to-zig/|title=A Reply to _The Road to Zig 1.0_|date=2019-05-13|website=www.gingerbill.org|language=en-gb|access-date=2020-02-11}}</ref><ref>{{Cite web|title=ziglang/zig|date=2020-02-11|url=https://github.com/ziglang/zig|website=GitHub|publisher=Zig Programming Language|access-date=2020-02-11}}</ref> supporting many of its native targets.<ref>{{Cite web|url=https://ziglang.org/#Tier-System|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref> The compiler is [[free and open-source software]] released under an [[MIT License]].<ref>{{Cite web|url=https://github.com/ziglang/zig|title=ziglang/zig|website=GitHub|language=en|access-date=2020-02-11}}</ref> The Zig compiler exposes the ability to compile C and C++ similarly to [[Clang]] with the commands <code>zig cc</code> and <code>zig c++</code>,<ref>{{Cite web|url=https://ziglang.org/download/0.6.0/release-notes.html#zig-cc|title=0.6.0 Release Notes|website=Ziglang.org|access-date=2020-04-19}}</ref> providing many headers including the [[C standard library]] (libc) and [[C++ Standard Library]] (libcxx) for many different platforms, allowing Zig'sZig’s <code>cc</code> and <code>c++</code> sub-commands to act as [[cross compiler]]s out of the box.<ref>{{Cite web|title='zig cc': a Powerful Drop-In Replacement for GCC/Clang - Andrew Kelley|url=https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html|access-date=2021-05-28|website=andrewkelley.me}}</ref><ref>{{Cite web|title=Zig Makes Go Cross Compilation Just Work|url=https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho|access-date=2021-05-28|website=DEV Community|date=24 January 2021 |language=en}}</ref>
==Other features==
Zig supports [[compile time]] [[Generic programming|generics]], [[Reflective programming|reflection]], and evaluation, [[Cross compiler|cross-compiling]], and [[manual memory management]].<ref>{{Cite web|url=https://ziglang.org/|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref> A major goal of the language is to improve on the [[C (programming language)|C language]],<ref name="roadtozig1.0" /><ref>{{Cite web|url=https://ziglang.org/#Zig-competes-with-C-instead-of-depending-on-it|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref> while also taking inspiration from [[Rust (programming language)|Rust]],<ref>{{Cite web |title=Zig programming language |url=https://sudonull.com/post/3683-Zig-programming-language |access-date=2020-02-11 |website=SudoNull |language=en}}</ref>{{sfn|Yegulalp|2016}} among others. Zig has many features for [[Low-level programming language|low-level programming]], notably packed structs (structs without padding between fields), arbitrary-width integers<ref>{{Cite web |url=https://www.theregister.co.uk/2020/04/24/llvm_project_adds_support_for/ |title=Keen to go _ExtInt? LLVM Clang compiler adds support for custom width integers |last1=Anderson |first1=Tim |date=2020-04-24 |website=www.theregister.co.uk |language=en |access-date=2024-12-30}}</ref> and multiple pointer types.<ref name="zigdocumentation">{{Cite web|url=https://ziglang.org/documentation/master/|title=Documentation|website=Ziglang.org|access-date=2020-04-24}}</ref>
 
Zig treats cross-compiling as a first-class use-case of the language.<ref name=zig /> This means any Zig compiler can compile runnable binaries for any of its target platforms, of which there are dozens. These include not only widely-used modern systems like [[ARM architecture family|ARM]] and [[x86-64]], but also [[PowerPC]], [[SPARC]], [[MIPS architecture|MIPS]], [[RISC-V]] and even the IBM [[z/Architecture]]s (S390). The toolchain can compile to any of these targets without installing additional software, all the needed support is in the basic system.<ref name=zigo/> The experimental support is also provided for less known platforms like AMD and Nvidia GPUs or PlayStation 4 and 5 (with various degree of support).
Zig is not just a new language: it also includes a C/C++ compiler, and can be used with either or both languages.<!-- "Zig competes with C instead of depending on it" -->
 
PlusCross-compilation is also available for variety of the operating systems (mostly desktop ones). Popular UNIX-like ones and Windows are officially supported (and documented), but (minimal) applications can and have been made for Android (with [[Android NDK]]), and programming foror [[iOS]] also possible.
== Drawbacks ==
Zig has a few drawbacks. If memory is not properly deallocated, it can result in memory leaks due to the lack of hidden control.<ref name="logrocket">{{cite web |last=Chigozie |first=Oduah |title=Comparing Rust vs. Zig: Performance, Safety, and More |url=https://blog.logrocket.com/comparing-rust-vs-zig-performance-safety-more/ |website=LogRocket Blog |date=2024-06-04 |access-date=2024-07-16}}</ref> The learning curve for Zig can be steep, especially for those unfamiliar with low-level programming concepts.<ref name="logrocket"/> Although Zig has a growing community, as of 2024, it remains a new language with areas for improvement in maturity, ecosystem and tooling.<ref name="logrocket"/> Interoperability with other languages may pose challenges, as it often requires extra effort to manage data marshaling and communication.<ref name="logrocket"/> Finally, the availability of learning resources is limited for complex use cases, though this is gradually improving as interest and adoption increase.<ref name="logrocket"/>
 
Zig uses [[LLVM]] (written in C++) as a backend for optimization. Since version 0.10 the Zig compiler is written in the Zig programming language, i.e., it is a [[self-hosting compiler]]. The self-hosted linker is tightly coupled with the self-hosted compiler.
==Versions==
Since version 0.10 the (new default) Zig compiler is written in the Zig programming language, i.e., it is a [[self-hosting compiler]], and that is a major new feature of that release. The older legacy [[Bootstrapping (compilers)|bootstrapping]] compiler, written in C++, is still an option but will not be in version 0.11. When compiling<!-- "Peak RSS: 9.6 GiB to 2.8 GiB (3.5× less memory used)" in docs "8.5 GB to 0.5 GB" in YouTube video may be wrong claim. --> with the new Zig compiler much less memory is used and it compiles a bit faster. The older, now legacy, C++ based compiler uses 3.5× more memory.
 
The previous [[Bootstrapping (compilers)|bootstrapping]] compiler, written in Zig and C++ using [[LLVM]] as a back-end,<ref>{{Cite web|url=https://www.gingerbill.org/article/2019/05/13/a-reply-to-the-road-to-zig/|title=A Reply to _The Road to Zig 1.0_|date=2019-05-13|website=www.gingerbill.org|language=en-gb|access-date=2020-02-11}}</ref><ref>{{Cite web|title=ziglang/zig|date=2020-02-11|url=https://github.com/ziglang/zig|website=GitHub|publisher=Zig Programming Language|access-date=2020-02-11}}</ref> supporting many of its native targets<ref>{{Cite web|url=https://ziglang.org/#Tier-System|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref>, was removed in version 0.11.
Zig's default backend for optimization is still [[LLVM]],<ref>New LLVM version 15, Zig legacy uses version 13</ref> and LLVM is written in C++. The Zig compiler with LLVM is 169 MiB{{Clarify|date=January 2025}}, vs without LLVM 4.4 MiB. Faster executable code is usually compiled with the new Zig-lang based compiler, its LLVM code generation is better, and it fixes many bugs, but there are also improvements for the older legacy compiler in version 0.10. The self-hosted linker is tightly coupled with the self-hosted compiler. The new version also adds some experimental (tier-3) support for AMD GPUs (there's also some lesser support for Nvidia GPUs and for PlayStation 4 and 5<!-- assumed since .ps5, .ps4, also vulkan, glsl450, nvptx and nvptx64 in source code. -->).
 
==Packages==
The older [[Bootstrapping (compilers)|bootstrapping]] ("stage1") compiler is written in Zig and [[C++]], using [[LLVM]] 13 as a back-end,<ref>{{Cite web|url=https://www.gingerbill.org/article/2019/05/13/a-reply-to-the-road-to-zig/|title=A Reply to _The Road to Zig 1.0_|date=2019-05-13|website=www.gingerbill.org|language=en-gb|access-date=2020-02-11}}</ref><ref>{{Cite web|title=ziglang/zig|date=2020-02-11|url=https://github.com/ziglang/zig|website=GitHub|publisher=Zig Programming Language|access-date=2020-02-11}}</ref> supporting many of its native targets.<ref>{{Cite web|url=https://ziglang.org/#Tier-System|title=The Zig Programming Language|website=Ziglang.org|access-date=2020-02-11}}</ref> The compiler is [[free and open-source software]] released under an [[MIT License]].<ref>{{Cite web|url=https://github.com/ziglang/zig|title=ziglang/zig|website=GitHub|language=en|access-date=2020-02-11}}</ref> The Zig compiler exposes the ability to compile C and C++ similarly to [[Clang]] with the commands <code>zig cc</code> and <code>zig c++</code>,<ref>{{Cite web|url=https://ziglang.org/download/0.6.0/release-notes.html#zig-cc|title=0.6.0 Release Notes|website=Ziglang.org|access-date=2020-04-19}}</ref> providing many headers including the [[C standard library]] (libc) and [[C++ Standard Library]] (libcxx) for many different platforms, allowing Zig's <code>cc</code> and <code>c++</code> sub-commands to act as [[cross compiler]]s out of the box.<ref>{{Cite web|title='zig cc': a Powerful Drop-In Replacement for GCC/Clang - Andrew Kelley|url=https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html|access-date=2021-05-28|website=andrewkelley.me}}</ref><ref>{{Cite web|title=Zig Makes Go Cross Compilation Just Work|url=https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho|access-date=2021-05-28|website=DEV Community|date=24 January 2021 |language=en}}</ref>
Before versionVersion 0.11.0, Zigbundles didan not have aexperimental [[package manager]], but in 0.11.0 an experimental version was released which was further extended in version 0.12.0. There is no official [[software repository|package repository]]; insteadis available. Instead a package is simply a URL pointingthat points to a [[Compressed file library|compressed file]]. that,Each when uncompressed,package includes a standard `build.zig` file (that the Zig compiler uses by convention to compile the source code) and, ideally, a `build.zig.zon` file whichcontaining ismetadata used to define thewith name and version of the package.
 
Plus the operating systems (mostly desktop ones) officially supported (and documented), (minimal) applications can and have been made for Android (with [[Android NDK]]), and programming for [[iOS]] also possible.
 
Before version 0.11.0, Zig did not have a [[package manager]], but in 0.11.0 an experimental version was released which was further extended in version 0.12.0. There is no official [[package repository]]; instead a package is simply a URL pointing to a [[Compressed file library|compressed file]] that, when uncompressed, includes a standard build.zig file (that the Zig compiler uses by convention to compile the source code) and, ideally, a build.zig.zon file which is used to define the name and version of the package.
 
Zig development is funded by the Zig Software Foundation (ZSF), a non-profit corporation with Andrew Kelley as president, which accepts donations and hires multiple full-time employees.<ref>{{Cite web |title=Jakub Konka on Twitter |url=https://twitter.com/kubkon/status/1377146321136537602 |archive-url=https://web.archive.org/web/20220410102319/https://twitter.com/kubkon/status/1377146321136537602 |archive-date=2022-04-10 |access-date=2021-05-28 |website=Twitter |language=en}}</ref><ref>{{Cite web|title=Announcing the Zig Software Foundation|url=https://ziglang.org/news/announcing-zig-software-foundation/|access-date=2021-05-28|website=Ziglang.org}}</ref><ref>{{Cite web|title=Sponsor ZSF|url=https://ziglang.org/zsf/|access-date=2021-05-28|website=Ziglang.org}}</ref>
 
==Examples==
Line 142 ⟶ 135:
return struct {
const Self = @This();
 
pub const Node = struct {
next: ?*Node = null,
Line 156 ⟶ 150:
list.first = new_node;
}
 
pub fn format(
list: Self,
Line 163 ⟶ 158:
) !void {
try out_stream.writeAll("( ");
 
var it = list.first;
while (it) |node| : (it = node.next) {
Line 172 ⟶ 168:
1,
);
 
try out_stream.writeAll(" ");
}
 
try out_stream.writeAll(")");
}
Line 181 ⟶ 179:
pub fn main() !void {
const ListU32 = LinkedList(u32);
 
var list = ListU32{};
var node1 = ListU32.Node{ .data = 1 };
var node2 = ListU32.Node{ .data = 2 };
var node3 = ListU32.Node{ .data = 3 };
 
list.prepend(&node1);
list.prepend(&node2);
list.prepend(&node3);
 
try stdout.print("{}\n", .{list});
try stdout.print("{b}\n", .{list});
Line 240 ⟶ 241:
);
 
// Prints "Hello Hello Hello "
try stdout.print("{s}\n", .{repeated});
}
Line 247:
* Output
*:<syntaxhighlight lang="output">
Hello Hello Hello
</syntaxhighlight>
 
==Name==
The name 'Zig'“Zig” was reportedly chosen through a process involving a [[Python (programming language)|Python]] script that randomly combined letters, starting with the letter 'Z'“Z” and followed by a vowel or 'Y'“Y”, in order to generate four-letter words. Despite the intended length, 'Zig'“Zig”, a three-letter word, was ultimately selected from the various combinations produced by the script.<ref>{{cite web |url=https://gist.github.com/andrewrk/73742bf4b8ed795c85ce |title=origin of the zig programming language name. by @andrewrk |author=andrewrk |date=2024-03-13 |access-date=2024-03-13}}</ref>
 
== Community ==
Line 254 ⟶ 257:
 
== Projects ==
* [[Bun (software)|Bun]] is a [[JavaScript]] and [[TypeScript]] runtime written in Zig, using [[Safari (web browser)|Safari]]'s’s JavaScriptCore [[virtual machine]].
* Ghostty<ref>{{Cite web |title=ghostty-org/ghostty |url= https://github.com/ghostty-org/ghostty |access-date=2024-12-27 |website=Github |language=en}}</ref> is a [[Terminal emulator|terminal emulator]] written in Zig.
* The TigerBeetle<ref>{{Cite web |title=tigerbeetle/tigerbeetle |url= https://github.com/tigerbeetle/tigerbeetle |access-date=2024-12-30 |website=Github |language=en}}</ref> financial transaction database is written in Zig.