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 to add two user input integer values in ziglang?

I have written a program that takes two values and sums them up and then displays them as a single value. but if add those two values it erroring in ziglang const std = @import("std"); const print = std.debug.print; const stdin =…
Aathiraj
  • 13
  • 5
0
votes
1 answer

Why do I need constCast here, is there better way?

What am I doing wrong in this example? In deinit() I am getting an error that expected is *MemoryPool but *const MemoryPool was given. const Tree = struct { node_pool: std.heap.MemoryPool(Node), pub fn init(allocator: Allocator) Tree { …
Ski
  • 14,197
  • 3
  • 54
  • 64
0
votes
1 answer

Zig import and use of C libraries: too many (conflicting?) ways

I'm wrapping a low level C library (networking) in zig. Building it requires a number of compiler flags, defines, etc.. For this I specify all that in my build.zip adding defines, paths, flags, source code files. This works 100%. Now, to actually…
ecwdw 23e3e23e
  • 375
  • 4
  • 11
0
votes
1 answer

Zig 'expected error union type, found 'void''

I have an array of a struct and I am being unable to sort it. The compiler returns error: expected error union type, found 'void'. var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; defer…
BelMat
  • 93
  • 8
0
votes
1 answer

Incorrect initial capacity for ArrayList

I've been going through ziglearn and have made my way to ArrayList. I understand the example given there but when I try something a bit more complex I run into errors. Based on the error it seems like my array doesn't have valid memory when it goes…
dangeroushobo
  • 1,291
  • 2
  • 16
  • 28
0
votes
0 answers

zig: linking symbol can't find

When try to write a freestanding program in zig, we have already defined a link script. (Actually os) However, I can't get the address of the symbol I defined in script. Some methods are tried but fails. Method 1, but segmentation fault on compiling…
CutieDeng
  • 31
  • 4
0
votes
1 answer

How to cross compile Rust code from Intel Mac to M1 Mac by Zig?

These days I'm curious about the cross-compile in Rust.As I know, it's very simple to do the same thing in Go or Zig.But in Rust, it's very difficult.I write Rust code in my Intel MacBook Pro, want to cross compile to get the executable file which…
JasonZhang
  • 68
  • 1
  • 10
0
votes
1 answer

compiler error with calling type method that takes empty context

I'm trying to call SomeClass().call, but am running into compiler errors. Specifically, running tests for const std = @import("std"); test "doing a thing" { { const calc_result = SomeClass().call(.{}); try…
CrepeGoat
  • 2,315
  • 20
  • 24
0
votes
0 answers

Compile Cython with zig cc on Windows - linking problem

I have tried to compile a piece of complex code with zig on Windows with no success (referencing this question as a starting point): cython base.py zig build-lib --verbose-link -DMS_WIN64 -dynamic -target x86_64-windows \ -I c:\python38\include\…
0
votes
1 answer

encountered `zig compiler bug: GenericPoison`?

Platform details macOS (Apple Silicon) zig versions (behavior identical on all) 0.10.0 aarch64 0.11-dev824 aarch64 Problem I wrote this code for basic composable iterators: pub fn RangeIterator(comptime NumberType: type) type { return…
CrepeGoat
  • 2,315
  • 20
  • 24
0
votes
1 answer

ncurses: program exiting when arrow key pressed

my question is exactly as the title says. My program exits right after I press an arrow up. Here's my program: pub fn main() !void { _ = c.initscr(); defer _ = c.endwin(); var i: u32 = 0; main_loop: while (true) : (i += 1) { …
kamkow1
  • 467
  • 2
  • 8
0
votes
1 answer

zig externs when using zig test for wasm

I have a Zig codebase that I'm compiling to WebAssembly with a build.zig like this: const std = @import("std"); pub fn build(b: *std.build.Builder) void { const mode = b.standardReleaseOptions(); const lib = b.addSharedLibrary("main",…
Dan Prince
  • 29,491
  • 13
  • 89
  • 120
0
votes
1 answer

how to convert []u8 to []const u8 in zig

I wanted to write fizzbuzz, but instead of just printing, store it in an array. The problem is converting the numbers to strings. I first tried with bufPrint, but It outputed white-space instead of a number. Then I tried out with allocPrint, it…
0
votes
1 answer

How can I cast '*anyopaque' to '[]const u8'?

I'm interacting with the SDL zig bindings I have a Surface, which contains a pointer to some pixels. In C, this is a void*, in zig it is an *anyopaque I want to pass this pointer-to-pixels to the UpdateTexture function, which in C accepts a void*…
Shish
  • 2,773
  • 19
  • 16
0
votes
1 answer

Should const string: *const [_:0]u8 = "infer size"; be compilable in zig?

While experimenting with the zig syntax, I noticed the type expression of string literals is omitted in all examples. Which is totally fine, I'm not saying it shouldn't be. const zig_string = "I am a string"; //it looks nice enough for sure and…
Gaai
  • 98
  • 1
  • 8