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

zig `@ptrToInt()` "error: unable to evaluate constant expression"

I'm attempting to call iotcl to get a terminal size like so: const std = @import("std"); fn ioctl_TIOCGWINSZ(fd: std.os.fd_t, ws: *std.os.linux.winsize) !void { while (true) { switch (std.os.errno(std.os.linux.ioctl(fd,…
user673679
  • 1,327
  • 1
  • 16
  • 35
0
votes
1 answer

Equivalent struct declaration in Zig

How would you declare the following struct equivalently in Zig? static struct lws_protocols protocols[] = { { "http", lws_callback_http_dummy, 0, 0 }, LWS_PLUGIN_PROTOCOL_MINIMAL, { NULL, NULL, 0, 0 } /* terminator */ }; Looking at the…
timbo
  • 13,244
  • 8
  • 51
  • 71
0
votes
1 answer

Global `comptime var` in Zig

In Zig, I can do this with no problems: fn foo() void { comptime var num: comptime_int = 0; num += 1; } But when I try declaring the variable outside of a function, I get a compile error: comptime var num: comptime_int = 0; fn foo() void…
Dull Bananas
  • 892
  • 7
  • 29
0
votes
1 answer

what is dark magic behind meta.Vectors?

After implementing some vector algebra based on generic algorithms and iterators, I decided to run some benchmarks. The idea was to compare custom vectors' with meta.Vectors' performance (doing addition and scaling). When vectors' size was set to…
osetr
  • 55
  • 1
  • 5
0
votes
1 answer

Zig 0.8.0 error: values of type '(enum literal)' must be comptime known

In Zig 0.8.0, When switching over u8 characters to get an enum type, I encountered a strange compiler error from this code: .op_type = switch(c1) { '+' => .add, '-' => .sub, '*' => .mul, '/' => .div, '%' => .mod, '^' => .exp, '|' =>…
Andrew
  • 13
  • 4
0
votes
1 answer

Why does this linker script produce off-by-one addresses?

I am writing some firmware code for an ARM Cortex-M0 microcontroller (specifically, the STM32F072B as part of the STM32 Discovery dev board). My linker script does not do anything special, it just fills out the vector table and then includes all the…
test
  • 11
0
votes
2 answers

why do user defined types in zig need to be const?

In case I need to declare a struct in Zig I have to prefix it with a const const Arith = struct { x: i32, y: i32, fn add(self: *Arith) i32 { return self.x + self.y; } }; test "struct test" { var testArith = Arith{ …
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26
0
votes
1 answer

Compiler Will Print Version But Freezes on Build

I am trying to follow this tutorial. I am running on MacOS Catalina, 10.15.3 , on a 13" Macbook pro from 2016. I downloaded the latest release from here for Mac. I unzipped the file, and moved the zig executable (but not the rest of the contents of…
David Sullivan
  • 462
  • 7
  • 16
0
votes
1 answer

Calling `std.math.clamp` gives compile error `error: unable to evaluate constant expression` in Zig

Why does this program fail to compile? Zig version 0.6.0. const std = @import("std"); fn get_value () f32 { return 1.0; } test "testcase" { const value: f32 = 1. + get_value() ; _ = std.math.clamp(value, 0.0, 255.0); } Gives compile…
Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183
0
votes
1 answer

what are the rules zig build-lib uses for shared objects filenames?

I have a sqlite extension file. The source is sqliteext/csv.c. When I build the lib with clang the output file is created at lib/csv.so. cc -g -fPIC -I /usr/local/include -shared sqliteext/csv.c -o lib/csv.so When I compile the lib using zig... zig…
Richard
  • 10,122
  • 10
  • 42
  • 61
0
votes
1 answer

Compiler design frontend calculation in the main function for Clang and Zig

I have started reading the source code of clang and zig-lang. Unfortunately, the source codes are complicated and I am not able to find out where is frontend of these compilers are called in the main function. In clang, the closer place I have found…
vmax
  • 1
0
votes
1 answer

In what programming languages are types treated as values?

The Zig Programming Language promotes the concept that "types are values" which seems like a very powerful concept to me and I wonder what other programming languages support this concept. I know that for example C++ templates can be used to pass…
eyelash
  • 3,197
  • 25
  • 33
-1
votes
0 answers

Can not add static files loading to my server

The below code is working fine with version 0.11.0: const std = @import("std"); const http = std.http; const log = std.log.scoped(.server); const server_addr = "127.0.0.1"; const server_port = 8000; // Run the server and handle incoming…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
-1
votes
2 answers

Multiline string is invalid

I'm writting the below code: pub fn main() !void { var array_list = std.ArrayList([]const u8).init(std.heap.page_allocator); defer array_list.deinit(); const cwd = fs.cwd(); const file = try cwd.createFile("files.zig", .{}); …
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
-1
votes
1 answer

I want to embed list of file but failed

I have the below code in order to embed a set of files: const std = @import("std"); pub const comptime_file_paths = [_][]const u8{ "www/x/in.txt", "www/emd.txt", "www/e2.txt", }; const EmbeddedFile = struct { path: []const u8, …
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
1 2 3
14
15