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
0
votes
1 answer

How are variables in a Zig struct meant to be declared?

While working on a program, I accidentally declared the variables in a struct incorrectly. The strange thing is that it actually worked and I'm not entirely sure why. I'm submitting this question to hopefully get some answers as to why this compiles…
0
votes
1 answer

Expected u3, but every varable is a u8

I am confused. Here is a minimal reproducable sample: pub fn main() void { const firstByte: u8 = 0b10000000; var col: u8 = 0; const bytes: u8 = 1; var colByte: u8 = bytes & (firstByte >> col); _ = colByte; } When compiling this, I get the…
Jomy
  • 514
  • 6
  • 22
0
votes
1 answer

MIPS instructions generated for zig `@mulAdd`?

System info zig version 0.12.0-dev.15+1c7798a3c zig flags: -O ReleaseFast -target mips-linux-gnu Background New to MIPS, trying to figure out some simple examples! I have the following zig code: export fn mul_add(num: f32) f32 { const result =…
CrepeGoat
  • 2,315
  • 20
  • 24
0
votes
2 answers

Can a function within a struct in Zig affect the struct itself?

I'm working on a small text adventure as a way to practice Zig. In it, I want the player to be able to move from one Location to another, with the locations stored within the World Map. While I can add a line to Main that accomplishes what I'm…
0
votes
1 answer

Why does zig function not accept null as function argument when type signature specifies parameter as nullable?

This is my zig code. I am just trying to read a file line by line pub fn main() anyerror!void { const path = "/home/testdata/testfile"; var f = try fs.openFileAbsolute(path, .{.mode = fs.File.OpenMode.read_only}); defer f.close(); …
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26
0
votes
1 answer

Floating point format options

I've just dipped my toe into Zig, but it seems to be lacking the floating point format options which are common in C and C++, namely the "f" and "g" options, so that, for example, (7.0 / 3.0) will display as 2.33333 by default, instead of…
Joe Abbate
  • 1,692
  • 1
  • 13
  • 19
0
votes
0 answers

Importing Zig packages

I was doing work for a project for a http server in Zig. I wanted to use sqlite3 as my database. I then looked sqlite client for Zig and found the github repo karlseguin/zqlite.zig and decided to use it. No matter what way I try it does not work.…
0
votes
1 answer

Using opencv in the zig, error: lld-link: undefined symbol: cv::imread

I’m trying to use opencv withing the zig programming language, I tried to follow what I read on this stackoverflow post to use the opencv c++ library in the zig language, I created a opencv_binding.h file that contains a simple function called…
Mahmoud Hany
  • 139
  • 1
  • 11
0
votes
1 answer

Binding string between zig/wasm and JavaScript

I used i32 binding perfectly between zig/wasm and JavaScript as below: //main.zig const std = @import("std"); extern fn print(a: i32) void; export fn add(a: i32, b: i32) i32 { print(a + b); // calling the JavaScript function return a +…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

The exported function is not shown at wasm

I wrote the below file: const std = @import("std"); pub export fn add(a: i32, b: i32) i32 { std.debug.print("add({}, {}) = {}\n", .{ a, b, a + b }); return a + b; } pub fn main() void { std.debug.print("Hello there from Zig!\n", .{}); …
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

How do I (unsafely) cast from `u64` to `i64` in Zig?

I have a u64 value that I need to cast to i64. @as, @intCast, and @truncate all give compiler errors because not all u64 values fit into i64. That's fair enough but in this case I need an i64 and I'm willing to accept an error/crash in the unlikely…
iafisher
  • 938
  • 7
  • 14
0
votes
1 answer

Capy-template build errors

I installed the capy-template with git on ubuntu. I'm getting zillions of windows errors. I'm totally new to zig and I have no clue as to why I'm getting windows errors. zig build followed by it's dump of errors. $ zig build zig build-exe okp Debug…
0
votes
1 answer

Comma in for loop

Why am I getting this syntax error in Zig? parse_integers.zig:21:18: error: expected ')', found ',' for (expected, list.items) |exp, actual| { Here is the code (copied and pasted from the Zig home page): const std = @import("std"); const…
8n8
  • 1,233
  • 1
  • 8
  • 21
0
votes
1 answer

How can I parse an integer from a string in Zig?

What is the best way to parse an integer from a string in Zig and specify the resulting integer type? const foo = "22"; How would I convert foo to an i32, for example?
JPlusPlus
  • 318
  • 1
  • 10
0
votes
1 answer

How to Return a Writer and a Reader from a function in zig?

I'm creating a simple program that reads from a file and then process that file. I saw a pattern for reading using a std.io.bufferedReader and std.io.fixedBufferStream().writer() So I'm trying to create a function to return both Writer and…
Douglas Correa
  • 1,015
  • 12
  • 25