# Explain

**URL:** https://ziggit.dev/c/explain/13.md?page=1

[Latest](https://ziggit.dev/latest.md) · [Categories](https://ziggit.dev/categories.md) · [Tags](https://ziggit.dev/tags.md)

**Page:** 2

---

## [Tagged Union test Active Field](https://ziggit.dev/t/tagged-union-test-active-field/17708)

<div class="topic-metadata">

**Author:** [@SpinTensor](https://ziggit.dev/u/SpinTensor)\
**Replies:** 3\
**Last updated:** [September 25, 2026, 10:58am UTC](https://ziggit.dev/t/tagged-union-test-active-field/17708 "2026-09-25T10:58:53Z")

</div>

Hi, i’m playing around with tagged unions. I wanted to write a test, to see if some functions I wrote correctly selected the active field of a tagged union. The value that was stored in the union does not matter, so I o…

---

## [Idiomatic way to deinit structures with allocated memory?](https://ziggit.dev/t/idiomatic-way-to-deinit-structures-with-allocated-memory/17640)

<div class="topic-metadata">

**Author:** [@psznm](https://ziggit.dev/u/psznm)\
**Replies:** 28\
**Last updated:** [September 24, 2026, 2:20pm UTC](https://ziggit.dev/t/idiomatic-way-to-deinit-structures-with-allocated-memory/17640 "2026-09-24T14:20:11Z")

</div>

So lets say I have a structure that only holds a pointer to an allocated memory and so the deinit is just freeing the memory and nothing else. What is the idiomatic way to do it? pub fn deinit(self: @This(), gpa: Alloca…

---

## [readAlloc does not update r.interface.seek and r.interface.end](https://ziggit.dev/t/readalloc-does-not-update-r-interface-seek-and-r-interface-end/17674)

<div class="topic-metadata">

**Author:** [@n4chh](https://ziggit.dev/u/n4chh)\
**Replies:** 4\
**Last updated:** [September 23, 2026, 8:57am UTC](https://ziggit.dev/t/readalloc-does-not-update-r-interface-seek-and-r-interface-end/17674 "2026-09-23T08:57:04Z")

</div>

Hi folks, I’m finding a confusing behaviour with the new IO reader API, during my zig development. Let me know if I’m missing something. I’m trying to read the headers of a kernel file using a buffer instead of a file r…

---

## [How to use \`build\_options\` inside test blocks](https://ziggit.dev/t/how-to-use-build-options-inside-test-blocks/17517)

<div class="topic-metadata">

**Author:** [@n4chh](https://ziggit.dev/u/n4chh)\
**Replies:** 4\
**Last updated:** [September 21, 2026, 6:59am UTC](https://ziggit.dev/t/how-to-use-build-options-inside-test-blocks/17517 "2026-09-21T06:59:13Z")

</div>

I’ve been reading through the testing docs and posts but I don’t understand how to use build options inside a test block without defining a test file specifically for it. I have the following line in my build code where…

---

## [Integer overflow in Io.Writer](https://ziggit.dev/t/integer-overflow-in-io-writer/17651)

<div class="topic-metadata">

**Author:** [@truly-not-taken](https://ziggit.dev/u/truly-not-taken)\
**Replies:** 7\
**Last updated:** [September 20, 2026, 8:08am UTC](https://ziggit.dev/t/integer-overflow-in-io-writer/17651 "2026-09-20T08:08:15Z")

</div>

I was trying to invent a toy zip-bomb while doing an exercise at Exercism and noticed an integer overflow in std.Io.Writer interface: test "Io.Writer does not integer overflow" { var w: std.Io.Writer.Discarding = .i…

---

## [Object pools with structs and arrays of varying sizes by using \`std.mem.bytesAsValue/Slice\`](https://ziggit.dev/t/object-pools-with-structs-and-arrays-of-varying-sizes-by-using-std-mem-bytesasvalue-slice/17648)

<div class="topic-metadata">

**Author:** [@chearon](https://ziggit.dev/u/chearon)\
**Replies:** 3\
**Last updated:** [September 19, 2026, 6:50pm UTC](https://ziggit.dev/t/object-pools-with-structs-and-arrays-of-varying-sizes-by-using-std-mem-bytesasvalue-slice/17648 "2026-09-19T18:50:00Z")

</div>

I’ve been experimenting with object pools that allow you to mint arbitrary types, very much inspired by Zig’s InternPool. Like InternPool, the backing buffer is \[\]u32 and the index is u32. The first API I added was addU…

---

## [Why does not optional error work the same way as optional integer?](https://ziggit.dev/t/why-does-not-optional-error-work-the-same-way-as-optional-integer/17650)

<div class="topic-metadata">

**Author:** [@truly-not-taken](https://ziggit.dev/u/truly-not-taken)\
**Replies:** 3\
**Last updated:** [September 19, 2026, 6:09am UTC](https://ziggit.dev/t/why-does-not-optional-error-work-the-same-way-as-optional-integer/17650 "2026-09-19T06:09:29Z")

</div>

I can not test optional error with expectEqual() while optional integers work fine: test "optional error" { const Error = error{Example}; const expected: Error = Error.Example; const actual: ?Error = Error.E…

---

## [Canonical Cross Compiling w/ System Dependencies, PKG Config, --sysroot and --search-prefix?](https://ziggit.dev/t/canonical-cross-compiling-w-system-dependencies-pkg-config-sysroot-and-search-prefix/17568)

<div class="topic-metadata">

**Author:** [@nat3Github](https://ziggit.dev/u/nat3Github)\
**Replies:** 0\
**Last updated:** [September 11, 2026, 3:52pm UTC](https://ziggit.dev/t/canonical-cross-compiling-w-system-dependencies-pkg-config-sysroot-and-search-prefix/17568 "2026-09-11T15:52:24Z")

</div>

a lot of projects use system dependencies - link xy.so or parse xy.h. some build steps even include host-tools-with-system-dependencies. As i understand the zig build system has following mechanisms: per module/step: …

---

## [Learning Zig](https://ziggit.dev/t/learning-zig/17549)

<div class="topic-metadata">

**Author:** [@Wauuuu](https://ziggit.dev/u/Wauuuu)\
**Replies:** 6\
**Last updated:** [September 10, 2026, 11:47am UTC](https://ziggit.dev/t/learning-zig/17549 "2026-09-10T11:47:10Z")

</div>

Hello guys, this is my first time learning Zig and programming. Why I am getting stuck at while loop in this code below if I typing let say “Jack”, sorry If my question doesn’t make sense and sorry my English is not that…

---

## [Too many VMA with SMPAllocator](https://ziggit.dev/t/too-many-vma-with-smpallocator/17529)

<div class="topic-metadata">

**Author:** [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Replies:** 4\
**Last updated:** [September 8, 2026, 12:31pm UTC](https://ziggit.dev/t/too-many-vma-with-smpallocator/17529 "2026-09-08T12:31:55Z")

</div>

Hello everyone! I want to explain to you a problem that I had and how did I solve it to get some feedback and check if my architecture might have been different! You can find the code I am describing at the repo, the b…

---

## [Design of Io.File.MultiReader?](https://ziggit.dev/t/design-of-io-file-multireader/17488)

<div class="topic-metadata">

**Author:** [@psznm](https://ziggit.dev/u/psznm)\
**Replies:** 2\
**Last updated:** [September 5, 2026, 8:33pm UTC](https://ziggit.dev/t/design-of-io-file-multireader/17488 "2026-09-05T20:33:50Z")

</div>

Why is MultiReader designed the way it is? Why contexts: \[n\]\[@sizeOf(Context)\]u8 align(@alignOf(Context)) and not just contexts: \[n\]Context Why the stuff with casting Buffer to Streams that hides the data? - I just rea…

---

## [What are we expecting in 0.17?](https://ziggit.dev/t/what-are-we-expecting-in-0-17/17438)

<div class="topic-metadata">

**Author:** [@IbrahimOuhamou](https://ziggit.dev/u/IbrahimOuhamou)\
**Replies:** 24\
**Last updated:** [September 4, 2026, 9:29pm UTC](https://ziggit.dev/t/what-are-we-expecting-in-0-17/17438 "2026-09-04T21:29:46Z")

</div>

a long time has passed since 0.16, I didn’t really find that many compilation errors upgrading from 0.16 (except ‘++’ and ‘\*\*’) it doesn’t have to be accurate, just what comes to mind

---

## [When to use builtins vs std.math? log, log10, log2, other?](https://ziggit.dev/t/when-to-use-builtins-vs-std-math-log-log10-log2-other/17433)

<div class="topic-metadata">

**Author:** [@elpablete](https://ziggit.dev/u/elpablete)\
**Replies:** 2\
**Last updated:** [September 1, 2026, 5:24am UTC](https://ziggit.dev/t/when-to-use-builtins-vs-std-math-log-log10-log2-other/17433 "2026-09-01T05:24:20Z")

</div>

Where should @builtins be used instead of std.math functions? And how to decide in a general?

---

## [(Dedicated function for) natural logarithm missing in standard library](https://ziggit.dev/t/dedicated-function-for-natural-logarithm-missing-in-standard-library/10976)

<div class="topic-metadata">

**Author:** [@jbe](https://ziggit.dev/u/jbe)\
**Replies:** 5\
**Last updated:** [August 31, 2026, 9:10pm UTC](https://ziggit.dev/t/dedicated-function-for-natural-logarithm-missing-in-standard-library/10976 "2026-08-31T21:10:40Z")

</div>

Continuing the discussion from Division by zero and Illegal Behavior: “ln” is std.math.log(). There’s also @log(), @log2() and @log10(). That isn’t quite correct. Apparently @log is the natural logarithm, @log2 is t…

---

## [Why not just \`.vtable = @ptrCast(vtable)\`?](https://ziggit.dev/t/why-not-just-vtable-ptrcast-vtable/17388)

<div class="topic-metadata">

**Author:** [@felixrabe](https://ziggit.dev/u/felixrabe)\
**Replies:** 19\
**Last updated:** [August 28, 2026, 8:30am UTC](https://ziggit.dev/t/why-not-just-vtable-ptrcast-vtable/17388 "2026-08-28T08:30:50Z")

</div>

I’m getting a grasp of interfaces, and am deeply unwilling to have to write self = @ptrCast(@alignCast(ptr)) all over the place. There MUST be a better way, no? ( See also: https://www.youtube.com/watch?v=2Q8gB2OXB2E ) …

---

## [What is the logic behind translate c function shortcuts? Is it bugged?](https://ziggit.dev/t/what-is-the-logic-behind-translate-c-function-shortcuts-is-it-bugged/17385)

<div class="topic-metadata">

**Author:** [@psznm](https://ziggit.dev/u/psznm)\
**Replies:** 5\
**Last updated:** [August 27, 2026, 9:48am UTC](https://ziggit.dev/t/what-is-the-logic-behind-translate-c-function-shortcuts-is-it-bugged/17385 "2026-08-27T09:48:37Z")

</div>

So I have recently realized translate-c generates methods on translated opaque structs (realized way too late because ZLS currently does not show them and I rely way too much on LSP). And it is very nice, because it also…

---

## [What kind of errors can or should be handled by the user facing code?](https://ziggit.dev/t/what-kind-of-errors-can-or-should-be-handled-by-the-user-facing-code/17384)

<div class="topic-metadata">

**Author:** [@MeKaLu](https://ziggit.dev/u/MeKaLu)\
**Replies:** 8\
**Last updated:** [August 27, 2026, 9:20am UTC](https://ziggit.dev/t/what-kind-of-errors-can-or-should-be-handled-by-the-user-facing-code/17384 "2026-08-27T09:20:05Z")

</div>

So, lately I have been thinking about API design and this is one of things I can’t really put my finger on it. For the sake of clarity, when I talk about “error” in this post I mean zig errors. Lets say (a hypothetical …

---

## [Why doesn't Zig have std.HashSet?](https://ziggit.dev/t/why-doesnt-zig-have-std-hashset/17363)

<div class="topic-metadata">

**Author:** [@giluis](https://ziggit.dev/u/giluis)\
**Replies:** 5\
**Last updated:** [August 26, 2026, 8:19am UTC](https://ziggit.dev/t/why-doesnt-zig-have-std-hashset/17363 "2026-08-26T08:19:21Z")

</div>

We can use std.HashMap with the Key=\<your set element type\> and Value=void, but seems hacky: the API isn’t as good as it could be e.g. you have to treat keys as your values and disregard a big part of the API. This issu…

---

## [Documentation Io.File.reader](https://ziggit.dev/t/documentation-io-file-reader/17346)

<div class="topic-metadata">

**Author:** [@isaias-dias-machado](https://ziggit.dev/u/isaias-dias-machado)\
**Replies:** 2\
**Last updated:** [August 23, 2026, 9:56pm UTC](https://ziggit.dev/t/documentation-io-file-reader/17346 "2026-08-23T21:56:22Z")

</div>

Hi, I am completely new to zig and wanted to give feedback on the documentation. I was trying to figure out how to read a file so I went over to the documentation and quickly found Io.File and the reader function, the …

---

## [Is \`resume\` a reserved word?](https://ziggit.dev/t/is-resume-a-reserved-word/17334)

<div class="topic-metadata">

**Author:** [@Southporter](https://ziggit.dev/u/Southporter)\
**Replies:** 2\
**Last updated:** [August 22, 2026, 7:32pm UTC](https://ziggit.dev/t/is-resume-a-reserved-word/17334 "2026-08-22T19:32:27Z")

</div>

I’ve run into this in two different projects now. The following fails to compile: // Doesn't compile pub fn resume() void {} // This does pub fn @"resume"() void {} Error: install └─ install repro └─ compile exe r…

---

## [The dot "." overuse](https://ziggit.dev/t/the-dot-overuse/17279)

<div class="topic-metadata">

**Author:** [@mp42](https://ziggit.dev/u/mp42)\
**Replies:** 29\
**Last updated:** [August 21, 2026, 2:09pm UTC](https://ziggit.dev/t/the-dot-overuse/17279 "2026-08-21T14:09:32Z")

</div>

Hello, this is my very first post. I’ve been a casual reader, and the community seems welcoming. (sorry for moving it around, I guess it should be on Explain, i’ll leave it here, if I’m wrong somebody please move to the…

---

## [Proposal: Better lossy casting for int-to-float](https://ziggit.dev/t/proposal-better-lossy-casting-for-int-to-float/17250)

<div class="topic-metadata">

**Author:** [@jpwol](https://ziggit.dev/u/jpwol)\
**Replies:** 24\
**Last updated:** [August 20, 2026, 1:05am UTC](https://ziggit.dev/t/proposal-better-lossy-casting-for-int-to-float/17250 "2026-08-20T01:05:27Z")

</div>

I’m creating a window/graphics library in Zig, and during this process I’ve hit some more headaches with the casting syntax. This stems from the changes with implicit int-to-float conversions (small enough integer can i…

---

## [Debugging Zig (with a debugger)](https://ziggit.dev/t/debugging-zig-with-a-debugger/7160)

<div class="topic-metadata">

**Author:** [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Replies:** 50\
**Last updated:** [August 19, 2026, 3:26am UTC](https://ziggit.dev/t/debugging-zig-with-a-debugger/7160 "2026-08-19T03:26:45Z")

</div>

Debugging Zig code is a bit of a dark art at present:. There’s no official documentation on the subject, and the lore involved is scattered among blog posts, video, Ziggit questions, the Discord, and so on. So I thought…

---

## [Add Unsafe Shift Operators](https://ziggit.dev/t/add-unsafe-shift-operators/17231)

<div class="topic-metadata">

**Author:** [@TheSuperFastOne](https://ziggit.dev/u/TheSuperFastOne)\
**Replies:** 3\
**Last updated:** [August 15, 2026, 7:53am UTC](https://ziggit.dev/t/add-unsafe-shift-operators/17231 "2026-08-15T07:53:20Z")

</div>

For some reason this couldn’t actually go in Brainstorming, cause it’s read-only. Anyways I have a working chess engine in C++, I wanted to see how Zig was, I was hearing some really nice things. Everything worked nicel…

---

## [Why does Deque.at return T instead of ?T](https://ziggit.dev/t/why-does-deque-at-return-t-instead-of-t/17146)

<div class="topic-metadata">

**Author:** [@jlarator](https://ziggit.dev/u/jlarator)\
**Replies:** 12\
**Last updated:** [August 13, 2026, 4:20pm UTC](https://ziggit.dev/t/why-does-deque-at-return-t-instead-of-t/17146 "2026-08-13T16:20:30Z")

</div>

I understand that the implementation for zig 0.16.0 is pub fn at(deque: \*const Self, index: usize) T { assert(index \< deque.len); return deque.buffer\[deque.bufferIndex(index)\]; } I would have expected to be som…

---

## [Auto vectorization of loops](https://ziggit.dev/t/auto-vectorization-of-loops/17164)

<div class="topic-metadata">

**Author:** [@minuanochamploo](https://ziggit.dev/u/minuanochamploo)\
**Replies:** 5\
**Last updated:** [August 12, 2026, 6:00am UTC](https://ziggit.dev/t/auto-vectorization-of-loops/17164 "2026-08-12T06:00:41Z")

</div>

Hi! I’m trying to understand why do I get loop unrolling instead of vectorization in this code (Compiler Explorer)? I definitely know that this C code will be vectorized: void sqr(const int\* restrict src, int\* restrict …

---

## [Unexpected size of union](https://ziggit.dev/t/unexpected-size-of-union/17018)

<div class="topic-metadata">

**Author:** [@giluis](https://ziggit.dev/u/giluis)\
**Replies:** 12\
**Last updated:** [August 11, 2026, 11:21pm UTC](https://ziggit.dev/t/unexpected-size-of-union/17018 "2026-08-11T23:21:26Z")

</div>

Hey! The following code prints 2. I don’t understand why that happens. I expected it to print 1, because the payloads are just 6 bits, meaning the discriminant / tag could be stored in the remaining 2 bits of the 8 bit…

---

## [Surprising side effect using print statements](https://ziggit.dev/t/surprising-side-effect-using-print-statements/17157)

<div class="topic-metadata">

**Author:** [@sickisonfire](https://ziggit.dev/u/sickisonfire)\
**Replies:** 4\
**Last updated:** [August 11, 2026, 6:49am UTC](https://ziggit.dev/t/surprising-side-effect-using-print-statements/17157 "2026-08-11T06:49:15Z")

</div>

Hey! While trying to learn more about zigs internpool i stumbled upon this issue, which i can’t wrap my head around. Simplified Code example: const key: Key = .{ .one = .{ .one = 1234, .two = "hello world" } }; …

---

## [When to use mutex or atomic](https://ziggit.dev/t/when-to-use-mutex-or-atomic/17150)

<div class="topic-metadata">

**Author:** [@jeffective](https://ziggit.dev/u/jeffective)\
**Replies:** 8\
**Last updated:** [August 9, 2026, 3:39pm UTC](https://ziggit.dev/t/when-to-use-mutex-or-atomic/17150 "2026-08-09T15:39:25Z")

</div>

My problem: I’ve got a field of a struct and I need to access the data across multiple io.async and io.concurrent. The data is small (\< 8 bits) I need to read / write from thread 1 and read / write from thread 2. I do …

---

## [Why are the Reader and Writer vtables intrusive as well?](https://ziggit.dev/t/why-are-the-reader-and-writer-vtables-intrusive-as-well/17003)

<div class="topic-metadata">

**Author:** [@paulrt](https://ziggit.dev/u/paulrt)\
**Replies:** 32\
**Last updated:** [August 7, 2026, 10:03pm UTC](https://ziggit.dev/t/why-are-the-reader-and-writer-vtables-intrusive-as-well/17003 "2026-08-07T22:03:53Z")

</div>

I think I get why the buffer needs to be intrusive but why does the vtable have to be as well? Why isn’t it a copyable handle more similar to the Allocator interface? something like this: // std/Io/Writer.zig const W…

[Previous page](https://ziggit.dev/c/explain/13.md)

[Next page](https://ziggit.dev/c/explain/13.md?page=2)
