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
0 answers

Failed to link a shared library

I have created a zig lib using the below code: //lib/src/main.zib const std = @import("std"); const file_paths = [_][]const u8{ "www/x/in.txt", "www/emd.txt", "www/index.html", "www/e2.txt", }; const EmbeddedFile = extern struct…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

Failed to define the target at build.zig

I'm at linux and want to cross compile for windows, I've the below that is working file for building the executable at linux: pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); // const target =…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

How to link against a static library?

I've a compiled static library, but don't have the code of it. I know the library embeds lots of files on compilation and looks something like this: //files.zig const std = @import("std"); pub const file_paths = [_][]const u8{ "www/x/in.txt", …
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

How to pass the `writer` between functions

I wnat to generate a file as below: const std = @import("std"); const comptime_file_paths = [_][]const u8{ "www/file1.txt", "www/file2.txt", // ... }; So I wrote the below code: const std = @import("std"); const fs = std.fs; const io =…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0
votes
1 answer

Make the compiler not optimize _ out

I'm writing a benchmark of a simple function. var timer = try std.time.Timer.start(); _ = f(); const elapsed = timer.read(); Unfortunately, the value marked with placeholder syntax gets optimized out, so elapsed equals zero. To fix this, i'm using…
Miiao
  • 751
  • 1
  • 8
0
votes
1 answer

Why is assembly code emitted by "zig cc -S" much larger than with gcc?

I have some very basic C code for which I want to view the equivalent assembly instructions. I'm interested to use zig cc because it can cross compile to M1 ARM, X86, etc. Here is my code: void variable_sort_2(int length, int *a) { if(length ==…
Purplejacket
  • 1,808
  • 2
  • 25
  • 43
0
votes
0 answers

How to connect to a database in Zig?

I was working on a cli type app with Zig, I couldn't find a way to connect with a database to store my data. Is there a native way to connect to a database with Zig? I couldn't find any docs through google. If there is not a native way to connect to…
0
votes
2 answers

How do I look at the assembly output of a Ziglang program?

Zig version 0.11.0-dev.3299+34865d693 The problem I want to be able to see the assembly output of my program, ideally with file names and line numbers mapping to the assembly instructions so I can quickly reason about where they've come from. Files…
SilbinaryWolf
  • 461
  • 4
  • 9
0
votes
1 answer

Incorrect alignment when destroy a value in Zig

I tried using the create and destroy functions mentioned in the documentation to create and destroy the value. However, a panic occurs during the destroy. Fullstack: run test: error: thread 2017663 panic: incorrect…
Hanaasagi
  • 219
  • 3
  • 7
0
votes
0 answers

zig error when compiling `comptime` tuples & array pointers

the issue Code: // Type your code here, or load an example. const std = @import("std"); export fn main() void { works(); //failsAtComptime(); } fn works() void { const test_cases = .{ [_]u8{}, [_]u8{0x01}, }; …
CrepeGoat
  • 2,315
  • 20
  • 24
0
votes
1 answer

How can I properly use Zig's buffered writer and reader without incomplete or strange output?

When using the buffered writer and reader, my output is sometimes incomplete or behaves strangely. This is seemingly caused by the string formatting of my final output message. After following this tutorial I created the following code. It simply…
0
votes
0 answers

Dockerfile Entrypoint not finding file

Im currently experimenting with UDP sockets in zig. The System consists of a test sender and a test reciever, both of which work fine and build fine on the host and in the containers, but somehow one of the twi generated executables is not copied…
TL044CN
  • 9
  • 1
0
votes
1 answer

Is there a way to have an ArrayList of a given struct in Zig?

I've thought about learning a little bit of Zig and was attempting to prototype maintaining a std.ArrayList of a struct that I created, but have been getting error{OutOfMemory}. I've tried using all the Google-Fu that I have to search for various…
sk3p7ic
  • 3
  • 3
0
votes
1 answer

How to pass a u8 buffer to a C function in Zig?

Let's say we have the following C function prototype: int do_something(char* buffer, int buff_size); How do I pass a zig u8 buffer to this function? Say, var buffer: [64]u8 = undefined; _ = c_lib.do_something(buffer.ptr, 64); I'm getting the…
c21253
  • 330
  • 4
  • 13
0
votes
1 answer

String buffers and slices in Zig

I'm aware that Zig for now is not ideal for amateurs, but all the same I've been trying to write a simple console program that asks the user his first name, then his last name, and finally prints "Your name is x and your last name is y" just to see…
Filippo
  • 15
  • 4