<s>
Zig	B-Application
is	O
an	O
imperative	B-Application
,	O
general-purpose	B-Language
,	O
statically	O
typed	O
,	O
compiled	B-Language
system	B-Language
programming	I-Language
language	I-Language
designed	O
by	O
Andrew	B-Application
Kelley	I-Application
.	O
</s>
<s>
It	O
is	O
intended	O
to	O
be	O
a	O
replacement	O
for	O
the	O
C	B-Language
programming	I-Language
language	I-Language
,	O
with	O
the	O
goals	O
of	O
being	O
even	O
smaller	O
and	O
simpler	O
to	O
program	O
in	O
while	O
also	O
offering	O
modern	O
features	O
,	O
new	O
optimizations	O
and	O
a	O
variety	O
of	O
safety	O
mechanisms	O
while	O
not	O
as	O
demanding	O
of	O
runtime	O
safety	O
as	O
seen	O
in	O
other	O
languages	O
.	O
</s>
<s>
It	O
is	O
distinct	O
from	O
languages	O
like	O
Rust	B-Application
or	O
Carbon	B-Application
,	O
which	O
have	O
similar	O
goals	O
in	O
terms	O
of	O
safety	O
and	O
functionality	O
,	O
but	O
aim	O
to	O
replace	O
C++	B-Language
,	O
not	O
C	B-Language
.	O
</s>
<s>
Features	O
adopted	O
from	O
modern	O
languages	O
include	O
the	O
addition	O
of	O
compile-time	B-Application
generic	B-Language
types	I-Language
,	O
allowing	O
functions	O
to	O
work	O
on	O
a	O
variety	O
of	O
data	O
,	O
along	O
with	O
a	O
small	O
set	O
of	O
new	O
compiler	O
directives	O
to	O
allow	O
access	O
to	O
the	O
information	O
about	O
those	O
types	O
using	O
reflection	B-Language
.	O
</s>
<s>
Another	O
set	O
of	O
additions	O
to	O
Zig	B-Application
is	O
intended	O
to	O
improve	O
code	O
safety	O
.	O
</s>
<s>
Like	O
C	B-Language
,	O
Zig	B-Application
does	O
not	O
include	O
garbage	B-General_Concept
collection	I-General_Concept
and	O
memory	O
handling	O
is	O
manual	O
.	O
</s>
<s>
The	O
primary	O
goal	O
of	O
Zig	B-Application
is	O
to	O
"	O
be	O
pragmatic	O
"	O
,	O
in	O
that	O
it	O
is	O
intended	O
to	O
be	O
a	O
better	O
solution	O
to	O
the	O
sorts	O
of	O
tasks	O
that	O
are	O
currently	O
solved	O
with	O
C	B-Language
.	O
A	O
primary	O
concern	O
in	O
that	O
respect	O
is	O
readability	O
;	O
Zig	B-Application
attempts	O
to	O
use	O
existing	O
concepts	O
and	O
syntax	O
wherever	O
possible	O
,	O
avoiding	O
the	O
addition	O
of	O
different	O
syntax	O
for	O
similar	O
concepts	O
.	O
</s>
<s>
Even	O
with	O
these	O
changes	O
,	O
Zig	B-Application
can	O
compile	O
into	O
and	O
against	O
existing	O
C	B-Language
code	O
;	O
C	B-Language
headers	O
can	O
be	O
included	O
in	O
a	O
Zig	B-Application
project	O
and	O
their	O
functions	O
called	O
,	O
and	O
Zig	B-Application
code	O
can	O
be	O
linked	O
into	O
C	B-Language
projects	O
by	O
including	O
the	O
compiler-built	O
headers	O
.	O
</s>
<s>
In	O
keeping	O
with	O
the	O
overall	O
design	O
philosophy	O
of	O
making	O
the	O
code	O
simple	O
and	O
easy	O
to	O
read	O
,	O
the	O
Zig	B-Application
system	O
as	O
a	O
whole	O
also	O
encompasses	O
a	O
number	O
of	O
stylistic	O
changes	O
compared	O
to	O
C	B-Language
and	O
other	O
C-like	O
languages	O
.	O
</s>
<s>
For	O
instance	O
,	O
the	O
Rust	B-Application
language	I-Application
has	O
operator	O
overloading	O
which	O
means	O
a	O
statement	O
like	O
might	O
actually	O
be	O
a	O
function	O
call	O
to	O
a	O
type	O
's	O
overloaded	O
version	O
of	O
the	O
plus	O
operator	O
.	O
</s>
<s>
In	O
Zig	B-Application
,	O
if	O
something	O
calls	O
a	O
function	O
it	O
looks	O
like	O
a	O
function	O
call	O
,	O
if	O
it	O
does	O
n't	O
it	O
does	O
n't	O
look	O
like	O
a	O
function	O
.	O
</s>
<s>
The	O
goals	O
of	O
Zig	B-Application
are	O
in	O
contrast	O
to	O
the	O
many	O
similar	O
languages	O
introduced	O
in	O
the	O
2020s	O
time-frame	O
,	O
like	O
Go	B-Application
,	O
Rust	B-Application
,	O
Carbon	B-Application
,	O
Nim	B-Application
and	O
many	O
others	O
.	O
</s>
<s>
Generally	O
,	O
these	O
languages	O
are	O
more	O
complex	O
with	O
additional	O
features	O
like	O
operator	O
overloading	O
,	O
functions	O
that	O
masquerade	O
as	O
values	O
(	O
properties	O
)	O
,	O
generic	B-Language
types	I-Language
and	O
many	O
other	O
features	O
intended	O
to	O
aid	O
the	O
construction	O
of	O
large	O
programs	O
.	O
</s>
<s>
These	O
sorts	O
of	O
features	O
have	O
more	O
in	O
common	O
with	O
C++'s	O
approach	O
,	O
and	O
these	O
languages	O
are	O
more	O
along	O
the	O
lines	O
of	O
that	O
language	O
.	O
</s>
<s>
Zig	B-Application
has	O
a	O
more	O
conservative	O
extension	O
of	O
the	O
type	O
system	O
,	O
supporting	O
compile-time	B-Application
generics	B-Language
and	O
accommodating	O
a	O
form	O
of	O
duck	B-Application
typing	I-Application
with	O
the	O
directive	O
.	O
</s>
<s>
One	O
of	O
the	O
primary	O
sources	O
of	O
bugs	O
in	O
C	B-Language
programs	I-Language
is	O
the	O
memory	B-General_Concept
management	I-General_Concept
system	O
,	O
based	O
on	O
malloc	B-Language
.	O
</s>
<s>
malloc	B-Language
sets	O
aside	O
a	O
block	O
of	O
memory	O
for	O
use	O
in	O
the	O
code	O
and	O
returns	O
a	O
reference	O
to	O
that	O
memory	O
as	O
a	O
pointer	O
.	O
</s>
<s>
There	O
is	O
no	O
system	O
to	O
ensure	O
that	O
memory	O
is	O
released	O
when	O
the	O
program	O
no	O
longer	O
needs	O
it	O
,	O
which	O
can	O
lead	O
to	O
programs	O
using	O
up	O
all	O
available	O
memory	O
,	O
a	O
memory	B-Error_Name
leak	I-Error_Name
.	O
</s>
<s>
More	O
common	O
,	O
and	O
sometimes	O
called	O
the	O
worst	O
mistake	O
in	O
computer	O
programming	O
,	O
is	O
the	O
null	O
pointer	O
error	O
,	O
when	O
the	O
memory	O
pointed	O
to	O
no	O
longer	O
exists	O
because	O
the	O
malloc	B-Language
failed	O
,	O
the	O
memory	O
was	O
released	O
by	O
other	O
code	O
,	O
or	O
a	O
host	O
of	O
other	O
problems	O
.	O
</s>
<s>
A	O
common	O
solution	O
to	O
these	O
problems	O
is	O
a	O
garbage	B-General_Concept
collector	I-General_Concept
(	O
GC	O
)	O
,	O
which	O
examines	O
the	O
program	O
for	O
pointers	O
to	O
previously	O
malloced	O
memory	O
,	O
and	O
removing	O
any	O
blocks	O
that	O
no	O
longer	O
have	O
anything	O
pointing	O
to	O
them	O
.	O
</s>
<s>
Although	O
this	O
greatly	O
reduces	O
,	O
or	O
even	O
eliminates	O
,	O
memory	O
errors	O
,	O
GC	O
systems	O
are	O
relatively	O
slow	O
compared	O
to	O
manual	B-Application
memory	I-Application
management	I-Application
,	O
and	O
have	O
unpredictable	O
performance	O
that	O
makes	O
them	O
unsuited	O
to	O
systems	B-Application
programming	I-Application
.	O
</s>
<s>
Another	O
solution	O
is	O
automatic	B-Language
reference	I-Language
counting	I-Language
(	O
ARC	O
)	O
,	O
which	O
implements	O
the	O
same	O
basic	O
concept	O
of	O
looking	O
for	O
pointers	O
to	O
removed	O
memory	O
,	O
but	O
does	O
so	O
at	O
malloc	B-Language
time	O
by	O
recording	O
the	O
number	O
of	O
pointers	O
to	O
that	O
block	O
,	O
meaning	O
there	O
does	O
not	O
need	O
to	O
perform	O
an	O
exhaustive	O
search	O
,	O
but	O
instead	O
adds	O
time	O
to	O
every	O
malloc	B-Language
and	O
release	O
operation	O
.	O
</s>
<s>
Zig	B-Application
aims	O
to	O
provide	O
performance	O
similar	O
or	O
better	O
than	O
C	B-Language
,	O
so	O
GC	O
and	O
ARC	O
are	O
not	O
suitable	O
solutions	O
.	O
</s>
<s>
So	O
,	O
for	O
instance	O
,	O
when	O
the	O
pointer	O
is	O
declared	O
it	O
is	O
set	O
to	O
"	O
unallocated	O
"	O
,	O
and	O
when	O
that	O
pointer	O
receives	O
a	O
value	O
from	O
a	O
malloc	B-Language
,	O
it	O
is	O
set	O
to	O
"	O
allocated	O
"	O
if	O
the	O
malloc	B-Language
succeeded	O
.	O
</s>
<s>
The	O
advantage	O
to	O
this	O
model	O
is	O
that	O
it	O
has	O
very	O
low	O
or	O
zero	O
overhead	O
;	O
the	O
compiler	O
has	O
to	O
create	O
the	O
code	O
to	O
pass	O
along	O
the	O
optional	O
type	O
when	O
pointers	O
are	O
manipulated	O
,	O
as	O
opposed	O
to	O
a	O
simple	O
pointer	O
,	O
but	O
this	O
allows	O
it	O
to	O
directly	O
express	O
possible	O
memory	O
problems	O
at	O
compile	B-Application
time	I-Application
with	O
no	O
runtime	O
support	O
.	O
</s>
<s>
For	O
instance	O
,	O
creating	O
a	O
pointer	O
with	O
a	O
null	O
value	O
and	O
then	O
attempting	O
to	O
use	O
it	O
is	O
perfectly	O
acceptable	O
in	O
C	B-Language
,	O
leading	O
to	O
null-pointer	O
errors	O
.	O
</s>
<s>
Another	O
change	O
for	O
memory	B-General_Concept
management	I-General_Concept
in	O
Zig	B-Application
is	O
that	O
the	O
actual	O
allocation	O
is	O
handled	O
through	O
s	O
describing	O
the	O
action	O
,	O
as	O
opposed	O
to	O
calling	O
the	O
memory	B-General_Concept
management	I-General_Concept
functions	O
in	O
libc	B-Language
.	O
</s>
<s>
For	O
instance	O
,	O
in	O
C	B-Language
if	O
one	O
wants	O
to	O
write	O
a	O
function	O
that	O
makes	O
a	O
string	O
containing	O
multiple	O
copies	O
of	O
another	O
string	O
,	O
the	O
function	O
might	O
look	O
like	O
this	O
:	O
</s>
<s>
In	O
the	O
code	O
,	O
the	O
function	O
would	O
examine	O
the	O
size	O
of	O
and	O
then	O
malloc	B-Language
that	O
length	O
to	O
set	O
aside	O
memory	O
for	O
the	O
string	O
it	O
will	O
build	O
.	O
</s>
<s>
That	O
malloc	B-Language
is	O
invisible	O
to	O
the	O
functions	O
calling	O
it	O
,	O
if	O
they	O
fail	O
to	O
later	O
release	O
the	O
memory	O
,	O
a	O
leak	O
will	O
occur	O
.	O
</s>
<s>
In	O
Zig	B-Application
,	O
this	O
might	O
be	O
handled	O
using	O
a	O
function	O
like	O
:	O
</s>
<s>
By	O
directly	O
expressing	O
the	O
allocator	O
as	O
an	O
input	O
,	O
memory	B-General_Concept
allocation	I-General_Concept
is	O
never	O
"	O
hidden	O
"	O
within	O
another	O
function	O
,	O
it	O
is	O
always	O
exposed	O
to	O
the	O
API	O
by	O
the	O
function	O
that	O
is	O
ultimately	O
calling	O
for	O
the	O
memory	O
to	O
be	O
allocated	O
.	O
</s>
<s>
No	O
allocations	O
are	O
performed	O
inside	O
Zig	B-Application
's	O
standard	B-Library
library	I-Library
.	O
</s>
<s>
This	O
can	O
allow	O
,	O
for	O
instance	O
,	O
small-object	O
allocators	O
that	O
do	O
not	O
use	O
the	O
operating	B-General_Concept
system	I-General_Concept
functions	O
that	O
normally	O
allocate	O
an	O
entire	O
memory	B-General_Concept
page	I-General_Concept
.	O
</s>
<s>
Optional	O
types	O
are	O
an	O
example	O
of	O
a	O
language	O
feature	O
that	O
offers	O
general	O
functionality	O
while	O
still	O
being	O
simple	O
and	O
generic	B-Language
.	O
</s>
<s>
In	O
Zig	B-Application
,	O
this	O
could	O
be	O
implemented	O
as	O
an	O
which	O
sets	O
the	O
variable	O
to	O
a	O
clear	O
"	O
not	O
been	O
called	O
"	O
value	O
.	O
</s>
<s>
Another	O
more	O
general	O
feature	O
of	O
Zig	B-Application
that	O
also	O
helps	O
manage	O
memory	O
problems	O
is	O
the	O
concept	O
of	O
,	O
which	O
marks	O
some	O
code	O
to	O
be	O
performed	O
at	O
the	O
end	O
of	O
a	O
function	O
no	O
matter	O
what	O
happens	O
,	O
including	O
possible	O
runtime	O
errors	O
.	O
</s>
<s>
Zig	B-Application
memory	B-General_Concept
management	I-General_Concept
avoids	O
hidden	O
allocations	O
.	O
</s>
<s>
Instead	O
,	O
heap	O
access	O
is	O
done	O
in	O
a	O
standard	B-Library
library	I-Library
,	O
explicitly	O
.	O
</s>
<s>
Zig	B-Application
promotes	O
an	O
evolutionary	O
approach	O
to	O
using	O
the	O
language	O
that	O
combines	O
new	O
Zig	B-Application
code	O
with	O
existing	O
C	B-Language
code	O
.	O
</s>
<s>
To	O
do	O
this	O
,	O
it	O
aims	O
to	O
make	O
interaction	O
with	O
existing	O
C	B-Language
libraries	I-Language
as	O
seamless	O
as	O
possible	O
.	O
</s>
<s>
Zig	B-Application
imports	O
its	O
own	O
libraries	O
with	O
the	O
directive	O
,	O
typically	O
in	O
this	O
fashion	O
:	O
</s>
<s>
Zig	B-Application
code	O
within	O
that	O
file	O
can	O
now	O
call	O
functions	O
inside	O
std	O
,	O
for	O
instance	O
:	O
</s>
<s>
To	O
work	O
with	O
C	B-Language
code	O
,	O
one	O
simply	O
replaces	O
the	O
with	O
:	O
</s>
<s>
const	O
c	B-Language
=	O
@cImport	O
(	O
@cInclude	O
(	O
"	O
soundio/soundio.h	O
"	O
)	O
)	O
;	O
</s>
<s>
The	O
Zig	B-Application
code	O
can	O
now	O
call	O
functions	O
in	O
the	O
soundio	O
library	O
as	O
if	O
they	O
were	O
native	O
Zig	B-Application
code	O
.	O
</s>
<s>
As	O
Zig	B-Application
uses	O
new	O
data	O
types	O
that	O
are	O
explicitly	O
defined	O
,	O
unlike	O
C	B-Language
's	O
more	O
generic	B-Language
and	O
,	O
a	O
small	O
number	O
of	O
directives	O
are	O
used	O
to	O
move	O
data	O
between	O
the	O
C	B-Language
and	O
Zig	B-Application
types	O
,	O
including	O
and	O
.	O
</s>
<s>
Zig	B-Application
treats	O
cross-compiling	B-Application
as	O
a	O
first-class	O
use-case	O
of	O
the	O
language	O
.	O
</s>
<s>
This	O
means	O
any	O
Zig	B-Application
compiler	O
can	O
compile	O
runnable	O
binaries	O
for	O
any	O
of	O
its	O
target	O
platforms	O
,	O
of	O
which	O
there	O
are	O
dozens	O
.	O
</s>
<s>
These	O
include	O
not	O
only	O
widely-used	O
modern	O
systems	O
like	O
ARM	B-Architecture
and	O
x86-64	B-Device
,	O
but	O
also	O
PowerPC	B-Architecture
,	O
SPARC	B-Architecture
,	O
MIPS	B-Device
,	O
RISC-V	B-Device
and	O
even	O
the	O
IBM	B-Device
z/Architectures	I-Device
(	O
S390	O
)	O
.	O
</s>
<s>
Zig	B-Application
supports	O
compile	B-Application
time	I-Application
generics	B-Language
,	O
reflection	B-Language
and	O
evaluation	O
,	O
cross-compiling	B-Application
,	O
and	O
manual	B-Application
memory	I-Application
management	I-Application
.	O
</s>
<s>
A	O
major	O
goal	O
of	O
the	O
language	O
is	O
to	O
improve	O
on	O
the	O
C	B-Language
language	I-Language
,	O
while	O
also	O
taking	O
inspiration	O
from	O
Rust	B-Application
,	O
among	O
others	O
.	O
</s>
<s>
Zig	B-Application
has	O
many	O
features	O
for	O
low-level	B-Language
programming	I-Language
,	O
notably	O
packed	O
structs	O
(	O
structs	O
without	O
padding	O
between	O
fields	O
)	O
,	O
arbitrary-width	O
integers	O
and	O
multiple	O
pointer	O
types	O
.	O
</s>
<s>
Zig	B-Application
is	O
not	O
just	O
a	O
new	O
language	O
:	O
it	O
also	O
includes	O
a	O
C/C	O
++	O
compiler	O
,	O
and	O
can	O
be	O
used	O
with	O
either	O
or	O
both	O
languages	O
.	O
</s>
<s>
Since	O
version	O
0.10	O
the	O
(	O
new	O
default	O
)	O
Zig	B-Application
compiler	O
is	O
written	O
in	O
Zig	B-Application
,	O
i.e.	O
,	O
it	O
is	O
a	O
self-hosting	O
compiler	O
,	O
and	O
that	O
is	O
a	O
major	O
new	O
feature	O
of	O
that	O
release	O
(	O
the	O
older	O
legacy	O
bootstrapping	B-Application
compiler	O
,	O
written	O
in	O
C++	B-Language
,	O
is	O
still	O
an	O
option	O
but	O
will	O
not	O
be	O
in	O
0.11	O
)	O
.	O
</s>
<s>
the	O
optimizer	O
)	O
is	O
still	O
LLVM	B-Application
(	O
now	O
version	O
15	O
,	O
legacy	O
uses	O
version	O
13	O
)	O
,	O
and	O
LLVM	B-Application
is	O
written	O
in	O
C++	B-Language
.	O
</s>
<s>
Zig	B-Application
(	O
i.e.	O
</s>
<s>
the	O
compiler	O
,	O
not	O
generated	O
code	O
from	O
it	O
)	O
with	O
LLVM	B-Application
is	O
169	O
MiB	O
,	O
vs	O
without	O
LLVM	B-Application
4.4	O
MiB	O
.	O
</s>
<s>
When	O
compiling	O
with	O
the	O
new	O
Zig	B-Application
compiler	O
much	O
less	O
memory	O
is	O
used	O
(	O
the	O
older	O
,	O
now	O
legacy	O
,	O
compiler	O
uses	O
3.5x	O
more	O
memory	O
)	O
,	O
and	O
it	O
compiles	O
a	O
bit	O
faster	O
.	O
</s>
<s>
Faster	O
executable	O
code	O
is	O
usually	O
compiled	B-Language
with	O
the	O
new	O
compiler	O
(	O
i.e.	O
</s>
<s>
its	O
LLVM	B-Application
code	O
generation	O
is	O
better	O
)	O
,	O
and	O
it	O
fixes	O
many	O
bugs	O
,	O
but	O
there	O
are	O
also	O
improvements	O
for	O
the	O
older	O
legacy	O
compiler	O
in	O
version	O
0.10	O
.	O
</s>
<s>
The	O
older	O
bootstrapping	B-Application
(	O
"	O
stage1	O
"	O
)	O
compiler	O
is	O
written	O
in	O
Zig	B-Application
and	O
C++	B-Language
,	O
using	O
LLVM	B-Application
13	O
as	O
a	O
back-end	O
,	O
supporting	O
many	O
of	O
its	O
native	O
targets	O
.	O
</s>
<s>
The	O
compiler	O
is	O
free	B-License
and	I-License
open-source	I-License
software	I-License
released	O
under	O
an	O
MIT	B-License
License	I-License
.	O
</s>
<s>
The	O
Zig	B-Application
compiler	O
exposes	O
the	O
ability	O
to	O
compile	O
C	B-Language
and	O
C++	B-Language
similarly	O
to	O
Clang	B-Application
with	O
the	O
commands	O
zig	B-Application
cc	O
and	O
zig	B-Application
c++	B-Language
,	O
providing	O
many	O
headers	O
including	O
the	B-Language
C	I-Language
standard	I-Language
library	I-Language
(	O
libc	B-Language
)	O
and	O
C++	B-Language
Standard	I-Language
Library	I-Language
(	O
libcxx	O
)	O
for	O
many	O
different	O
platforms	O
,	O
allowing	O
Zig	B-Application
's	O
cc	O
and	O
c++	B-Language
sub-commands	O
to	O
act	O
as	O
cross	B-Application
compilers	I-Application
out	O
of	O
the	O
box	O
.	O
</s>
<s>
Plus	O
the	O
operating	B-General_Concept
systems	I-General_Concept
(	O
mostly	O
desktop	O
ones	O
)	O
officially	O
supported	O
(	O
and	O
documented	O
)	O
,	O
(	O
minimal	O
)	O
applications	O
can	O
and	O
have	O
been	O
made	O
for	O
Android	O
(	O
with	O
Android	B-Application
NDK	I-Application
,	O
and	O
programming	O
for	O
iOS	B-Application
also	O
possible	O
)	O
.	O
</s>
<s>
Zig	B-Application
does	O
n't	O
have	O
its	O
own	O
official	O
package	O
manager	O
(	O
non-official	O
ones	O
exist	O
)	O
,	O
but	O
a	O
standard	O
one	O
has	O
a	O
milestone	O
for	O
0.12	O
.	O
</s>
<s>
Zig	B-Application
development	O
is	O
funded	O
by	O
the	O
Zig	B-Application
Software	O
Foundation	O
(	O
ZSF	O
)	O
,	O
a	O
non-profit	O
corporation	O
with	O
Andrew	B-Application
Kelley	I-Application
as	O
president	O
,	O
which	O
accepts	O
donations	O
and	O
hires	O
multiple	O
full-time	O
employees	O
.	O
</s>
<s>
is	O
a	O
JavaScript	B-Language
and	O
TypeScript	B-Language
runtime	O
written	O
in	O
Zig	B-Application
,	O
using	O
Safari	B-Application
's	O
JavaScriptCore	O
virtual	B-Architecture
machine	I-Architecture
.	O
</s>
