Questions tagged [zig]

Zig is an open-source programming language designed for robustness, optimality, and clarity.

Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

Website:

Documentation:

Zig has many features for low-level programming, notably: packed structs (structs without padding between fields), arbitrary width integers and multiple pointer types. Zig has no hidden control flow, no hidden memory alocation, no macros (but therefor compile time code execution)

212 questions
2
votes
1 answer

Create a struct with String parameter

I just want to create a struct with variable String (utf-8 text). const Person = struct { name: [_]u8, }; Is it possible? Or I have to set maximum length of string (e.g. name: [255]u8;)? When I pass to compiler it says: person.zig:5:12:…
somenxavier
  • 1,206
  • 3
  • 20
  • 43
2
votes
2 answers

Correct BigInt Fibonacci Implementation in Zig Lang

I am new to Zig Lang, and I was searching for an existing implementation for Big Int Fibonacci to no avail. So, I went through the source code of Zig Lang, Specifically Big Int Source & Big Int Tests, to figure out how to use the Big Int…
Abhijit Kar ツ
  • 1,732
  • 1
  • 11
  • 24
2
votes
1 answer

How to re-export functions from a third-party module

I have a module foo.zig which is useful but I want to augment it with more functions, without modifying it, so I created foo-wrapper.zig that has one or two more functions, and foo.zig has dozens of functions. How do I re-export (with pub or…
André Staltz
  • 13,304
  • 9
  • 48
  • 58
2
votes
0 answers

Can the Zig "HellOS" example be ported to C as a single file without a .s support file?

The OS Development wiki at https://wiki.osdev.org/Bare_Bones contains a sample of writing a very basic "Hello World" x86 kernel using a combination of an assembly file and a C file. https://github.com/andrewrk/HellOS shows a similar project, but…
Mark Green
  • 1,310
  • 12
  • 19
2
votes
3 answers

import zig package from another zig package

I can import an package in my executable with exe.addPackagePath("name", "path") and usae it with const name = @import("name");. Now I want to include the package in another package, but I don´t understand how. Can I create an object for the package…
B_old
  • 1,141
  • 3
  • 12
  • 26
2
votes
1 answer

Implementing a basic classic try-catch in Zig

How do I implement the classic try-catch error handling in Zig? For example. How to solve this error and only execute append when no error occurs? var stmt = self.statement() catch { self.synchronize(); // Only execute this when there is an…
Himujjal
  • 1,581
  • 1
  • 14
  • 16
2
votes
2 answers

How to concat two string literals at compile time in Zig?

How to do concat the following strings whose length are known at compile time in Zig? const url = "https://github.com/{}/reponame"; const user = "Himujjal"; const final_url = url + user; // ??
Himujjal
  • 1,581
  • 1
  • 14
  • 16
2
votes
1 answer

How to build and link to CGLM from Zig with or without SIMD intrinsics

I would like to link and use cglm C library. I'm working on windows without msvc (so targeting gnu C ABI) with Zig 0.7.1 and Zig 0.8.0 (master) without any luck. I have been able to build CGLM static library from Zig build.zig but no luck linking…
2
votes
1 answer

does zig cc expose a linker (ld)?

I am trying to compile xz with zig cc on Linux without build tools except zig: $ zig version 0.8.0-dev.1039+bea791b63 $ export CC="zig cc" $ ./configure <...> checking for ld used by zig cc... no configure: error: no acceptable ld found in…
Motiejus Jakštys
  • 2,769
  • 2
  • 25
  • 30
2
votes
1 answer

Is it possible to convert a std.builtin.TypeInfo.Error back to its error value?

The struct std.builtin.TypeInfo.Error only contains a name field. And since no @nameToError function exists, I don't see a way to convert this to it's error value. In version 0.6 of zig that struct has a value field, which holds the number to…
phil
  • 1,377
  • 2
  • 9
  • 14
2
votes
1 answer

Access Structs Returned by Value from C Functions in Zig 0.7.0

Here's some C code that I import into Zig via @cImport on linux-x86_64, in Zig 0.7.0. When I directly create a struct Point struct in Zig it works as expected, but when I return one by value from the getPoint method have bad data (see "output"…
2
votes
2 answers

Seg fault while trying to print strings in a loop

I'm currently learning Zig (having very little experience in C) and I'm doing some experiments with strings to make sure I understand the concept properly. For example, since strings are arrays of u8 I figured out that I can print the character 'C'…
2
votes
1 answer

Error to append a converted u8 (from i8) to an ArrayList, only in a specific program

I have to convert an i8 number to u8 (@intCast()), so that it is added to a ArrayList (I don't care how this conversion will be done if the number is negative). Running this program with zig test intcast.zig it returns All 1 tests passed.: const std…
2
votes
0 answers

OpenGL Vertex Array Object failing to bind Vertex Buffer

I am learning OpenGL through https://learnopengl.com/. From that site, and my research on the internet while trying to solve this problem, I have learned that Vertex Array Objects are useful because you can bind one with glBindVertexArray, and Any…
phil
  • 1,416
  • 2
  • 13
  • 22
2
votes
0 answers

Adding symbols around a debug section causes binary to triple in size

I would like to add a start and end symbol around each debug info section so that I can access them from my program. I tried the following scheme: .debug.info ALIGN(4K) : { DEBUG_INFO_START = .; *(.debug.info) DEBUG_INFO_END =…
SamTebbs33
  • 5,507
  • 3
  • 22
  • 44