Relative Content

Tag Archive for zig

Can’t understand how comptime works in my code

I have a simple enum, that has a method to “convert” it to a colored string, but whenever I try to use it, I get an error “unable to resolve comptime value”, though this code is not intended to be ran on comptime, but even if zig is calculating all possible return values at comptime (since there is a very finite number of those) of this function:

How to organize large projects in Zig language

I used to break down my large c/c++ projects with CMake and then add each part to main project using add_submodule command (the smaller parts were static or dynamic libraries). Also I used the same solution to use third-party libraries in my project.

How to split utf8 strings

I’m new to zig and learning it atm. When I use std.mem.splitAny or splitSequence or tokenize to split a console input string with a space as delimiter, it returns garbage. So I tried to write my own unicode split function. Here it is:

Dynamic dispatch and vtables. Problem accessing types

I’ve been trying to create a system where i can store different types of data as “bundles”. The input order should not matter (i sort the input by their type), and i should be able to get only parts of the data.

Why is there very little use of pointers as parameters in the standard library of Zig?

While reading some of the standard library source code, I have encountered very little use of pointers for function parameters, even with const, unless that specific parameter is edited by the function. From my perspective, it doesn’t seem very efficient as you are making a complete copy of the argument (obviously a shallow copy). So why is this? Is it better than passing something as a constant pointer, or is it just the “idiomatic Zig way”?