# \#comptime

**URL:** https://ziggit.dev/tag/comptime/9.md

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

---

## [I've painted myself into a corner with comptime and I'm seeking advice](https://ziggit.dev/t/ive-painted-myself-into-a-corner-with-comptime-and-im-seeking-advice/18012)

<div class="topic-metadata">

**Author:** [@grurbo](https://ziggit.dev/u/grurbo)\
**Replies:** 13\
**Last updated:** [October 22, 2026, 4:40pm UTC](https://ziggit.dev/t/ive-painted-myself-into-a-corner-with-comptime-and-im-seeking-advice/18012 "2026-10-22T16:40:57Z")

</div>

I didn’t know it was possible to create a comptime program that was so large it would no longer compile. I kept raising @setEvalBranchQuota to fix it, but now, by passing maxInt(u32), the compiler just segfaults. I have …

---

## [ZGC: Tensor Graphs/Numerical computation compiler](https://ziggit.dev/t/zgc-tensor-graphs-numerical-computation-compiler/17866)

<div class="topic-metadata">

**Author:** [@krypticlogan](https://ziggit.dev/u/krypticlogan)\
**Replies:** 0\
**Last updated:** [October 6, 2026, 7:15am UTC](https://ziggit.dev/t/zgc-tensor-graphs-numerical-computation-compiler/17866 "2026-10-06T07:15:48Z")

</div>

Zig-Graph-Compiler(ZGC): Started as a specialized runtime for neural network graphs, and pivoted to a tensor graph compiler, but really they’re the same thing? https://github.com/krypticlogan/zig-graph-compiler Around…

---

## [More comptime?](https://ziggit.dev/t/more-comptime/17729)

<div class="topic-metadata">

**Author:** [@trampinheavy](https://ziggit.dev/u/trampinheavy)\
**Replies:** 5\
**Last updated:** [September 30, 2026, 4:55am UTC](https://ziggit.dev/t/more-comptime/17729 "2026-09-30T04:55:59Z")

</div>

I’m just curious why I can’t do something like have a variable that is defined at comptime but still a variable? As long as it’s only modified after comptime it shouldn’t matter that it is a var, but the compiler won’t l…

---

## [Issue with opaque {} in inline for](https://ziggit.dev/t/issue-with-opaque-in-inline-for/17732)

<div class="topic-metadata">

**Author:** [@Gornak40](https://ziggit.dev/u/Gornak40)\
**Replies:** 7\
**Last updated:** [September 27, 2026, 6:19pm UTC](https://ziggit.dev/t/issue-with-opaque-in-inline-for/17732 "2026-09-27T18:19:50Z")

</div>

I know that opaque {} types are assigned unique identifiers for different literals. I’m wondering why a literal inside inline for loop is reused? In this code snippet foo() returns equal type ids, while bar() returns di…

---

## [Static comptime variable? (preserve state between two comptime function calls)](https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691)

<div class="topic-metadata">

**Author:** [@psznm](https://ziggit.dev/u/psznm)\
**Replies:** 17\
**Last updated:** [September 24, 2026, 8:32am UTC](https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691 "2026-09-24T08:32:25Z")

</div>

Is it possible to preserve some comptime state between comptime function calls? What I am trying to do is to create a logger wrapper that provides IDs to log messages based on their name in the struct. const UnnamedLog…

---

## [Composing a string during run time](https://ziggit.dev/t/composing-a-string-during-run-time/17327)

<div class="topic-metadata">

**Author:** [@gDator](https://ziggit.dev/u/gDator)\
**Replies:** 4\
**Last updated:** [August 22, 2026, 5:12pm UTC](https://ziggit.dev/t/composing-a-string-during-run-time/17327 "2026-08-22T17:12:27Z")

</div>

I tried composing a string during comptime. The string is dependent on a type given. Currently i m trying somthing like this: const size: usize = str: { comptime { var le…

---

## [How can you generate constant data in 0.16.0](https://ziggit.dev/t/how-can-you-generate-constant-data-in-0-16-0/17297)

<div class="topic-metadata">

**Author:** [@kmnn](https://ziggit.dev/u/kmnn)\
**Replies:** 2\
**Last updated:** [August 20, 2026, 12:37am UTC](https://ziggit.dev/t/how-can-you-generate-constant-data-in-0-16-0/17297 "2026-08-20T00:37:45Z")

</div>

In zig 0.15.2, you could replicate the &.{ 1, 2, 3 } syntax with metaprogramming. const a: \[\]const usize = &.{100, 17}; std.debug.print("{any}\\n", .{a}); const b: \[\]const usize = &@Type(.{ .@"struct" = .{ .layout …

---

## [Zenfmt: A universal document converter engine built with Zig (comptime SoA, zero-alloc filters, freestanding WASM, and single binary REST server)](https://ziggit.dev/t/zenfmt-a-universal-document-converter-engine-built-with-zig-comptime-soa-zero-alloc-filters-freestanding-wasm-and-single-binary-rest-server/17202)

<div class="topic-metadata">

**Author:** [@insanai](https://ziggit.dev/u/insanai)\
**Replies:** 3\
**Last updated:** [August 12, 2026, 8:05pm UTC](https://ziggit.dev/t/zenfmt-a-universal-document-converter-engine-built-with-zig-comptime-soa-zero-alloc-filters-freestanding-wasm-and-single-binary-rest-server/17202 "2026-08-12T20:05:59Z")

</div>

ZENFMT: Hi Everyone, I would like to share. A universal document conversion library, CLI, server, Python package, and WebAssembly module built entirely in Zig. The project is directly inspired by John MacFarlane’s p…

---

## [Unsure how to pass slices (or pointers in general) at comptime](https://ziggit.dev/t/unsure-how-to-pass-slices-or-pointers-in-general-at-comptime/17102)

<div class="topic-metadata">

**Author:** [@2000ae](https://ziggit.dev/u/2000ae)\
**Replies:** 6\
**Last updated:** [August 7, 2026, 1:43am UTC](https://ziggit.dev/t/unsure-how-to-pass-slices-or-pointers-in-general-at-comptime/17102 "2026-08-07T01:43:18Z")

</div>

Hi all, I’m trying to mock up a quick wrapper around bufPrint to be able to turn a formatted string into unicode codepoints. Here is the code that intends to do that: pub fn formatAsCodepoints(comptime out\_buffer: \[\]Co…

---

## [Function signature that uses variadic args as part of the interface vtable](https://ziggit.dev/t/function-signature-that-uses-variadic-args-as-part-of-the-interface-vtable/17094)

<div class="topic-metadata">

**Author:** [@cciva](https://ziggit.dev/u/cciva)\
**Replies:** 7\
**Last updated:** [August 5, 2026, 6:58pm UTC](https://ziggit.dev/t/function-signature-that-uses-variadic-args-as-part-of-the-interface-vtable/17094 "2026-08-05T18:58:47Z")

</div>

Hi all, Newbie here, I’m currently trying out/ learning zig, so please bear with me. This might have been answered before, but I couldn’t find anything related to my specific scenario. As an exercise (interfaces, compt…

---

## [Zig unable to resolve comptime value in an if expression for two arguments](https://ziggit.dev/t/zig-unable-to-resolve-comptime-value-in-an-if-expression-for-two-arguments/17058)

<div class="topic-metadata">

**Author:** [@SquidBow](https://ziggit.dev/u/SquidBow)\
**Replies:** 3\
**Last updated:** [August 4, 2026, 6:44am UTC](https://ziggit.dev/t/zig-unable-to-resolve-comptime-value-in-an-if-expression-for-two-arguments/17058 "2026-08-04T06:44:42Z")

</div>

This compiles if (replacement.items.len == 0) { try replacement.insertSlice(allocator, 3, "foo"); } else if (containsString(&keywords, replacement.items)) { try replacement.insertSlice(allocator, 3, "foo"); } b…

---

## [Dealing with a closed set of types in runtime](https://ziggit.dev/t/dealing-with-a-closed-set-of-types-in-runtime/17043)

<div class="topic-metadata">

**Author:** [@nadakan1019](https://ziggit.dev/u/nadakan1019)\
**Replies:** 6\
**Last updated:** [August 3, 2026, 2:57am UTC](https://ziggit.dev/t/dealing-with-a-closed-set-of-types-in-runtime/17043 "2026-08-03T02:57:45Z")

</div>

I want to have a “system” that can contain a closed set of types of objects, my idea here is, that all the types of objects this “system” can hold must meet some requirements for them to be useful-for instance a “GameUp…

---

## [Partial workaround for missing \`decls\` param to \`@Struct\`](https://ziggit.dev/t/partial-workaround-for-missing-decls-param-to-struct/16758)

<div class="topic-metadata">

**Author:** [@ashley.h](https://ziggit.dev/u/ashley.h)\
**Replies:** 10\
**Last updated:** [July 19, 2026, 1:11pm UTC](https://ziggit.dev/t/partial-workaround-for-missing-decls-param-to-struct/16758 "2026-07-19T13:11:05Z")

</div>

I just had plain c.sdl\* functions and I decided that I want to strip them to sdl.\* Gnerally it is just about trying to find a way to create decls for comptime generated struct (As a probably a lot of people tried: examp…

---

## [Embed binary data at compile time](https://ziggit.dev/t/embed-binary-data-at-compile-time/16729)

<div class="topic-metadata">

**Author:** [@schlyngel](https://ziggit.dev/u/schlyngel)\
**Replies:** 23\
**Last updated:** [July 17, 2026, 1:22pm UTC](https://ziggit.dev/t/embed-binary-data-at-compile-time/16729 "2026-07-17T13:22:36Z")

</div>

Hey :slight\_smile: this is my first Post and also my first attempts at metaprogramming. For my Project im working on, i needed some icons and found them in the form of SVGs. Because i want this project to be small and …

---

## [Static Maps](https://ziggit.dev/t/static-maps/16655)

<div class="topic-metadata">

**Author:** [@tnaums](https://ziggit.dev/u/tnaums)\
**Replies:** 8\
**Last updated:** [July 12, 2026, 8:05am UTC](https://ziggit.dev/t/static-maps/16655 "2026-07-12T08:05:07Z")

</div>

I need to create a map with amino acids as keys and values that represent their mass (f32). Amino acids, the building blocks of proteins, are represented by a single capital letter–there are just 20 of them. I created th…

---

## [Half-open ranges in switch, and empty switch ranges without compile error](https://ziggit.dev/t/half-open-ranges-in-switch-and-empty-switch-ranges-without-compile-error/16549)

<div class="topic-metadata">

**Author:** [@dpirch](https://ziggit.dev/u/dpirch)\
**Replies:** 3\
**Last updated:** [July 7, 2026, 2:13am UTC](https://ziggit.dev/t/half-open-ranges-in-switch-and-empty-switch-ranges-without-compile-error/16549 "2026-07-07T02:13:51Z")

</div>

There is this isFieldOptional example function in the docs (I want to do something similar): fn isFieldOptional(comptime T: type, field\_index: usize) !bool { const fields = @typeInfo(T).@"struct".fields; return …

---

## [Confusion about comptime vs runtime evaluation](https://ziggit.dev/t/confusion-about-comptime-vs-runtime-evaluation/16493)

<div class="topic-metadata">

**Author:** [@blank](https://ziggit.dev/u/blank)\
**Replies:** 15\
**Last updated:** [July 5, 2026, 5:05am UTC](https://ziggit.dev/t/confusion-about-comptime-vs-runtime-evaluation/16493 "2026-07-05T05:05:20Z")

</div>

I stumbled into this wierdness: if (!(ArchetypeHeader.arrayable())) @compileError(std.fmt.comptimePrint("{any}", .{ArchetypeHeader.arrayable()})); And I get a compile error, no problem the fu…

---

## [Confused about @tagName and comptime behavior](https://ziggit.dev/t/confused-about-tagname-and-comptime-behavior/16413)

<div class="topic-metadata">

**Author:** [@fsgr](https://ziggit.dev/u/fsgr)\
**Replies:** 5\
**Last updated:** [July 1, 2026, 12:31am UTC](https://ziggit.dev/t/confused-about-tagname-and-comptime-behavior/16413 "2026-07-01T00:31:39Z")

</div>

I’m working on a library for a project targeting Arm Cortex-M. I want to convert a enum value to an integer based on the enum tag name. For example: const E = enum { mul4, mul8, mul16, }; // This should ma…

---

## [Is there anyway to get function and arg idents at comptime?](https://ziggit.dev/t/is-there-anyway-to-get-function-and-arg-idents-at-comptime/16382)

<div class="topic-metadata">

**Author:** [@Shrimo](https://ziggit.dev/u/Shrimo)\
**Replies:** 3\
**Last updated:** [June 27, 2026, 1:19pm UTC](https://ziggit.dev/t/is-there-anyway-to-get-function-and-arg-idents-at-comptime/16382 "2026-06-27T13:19:32Z")

</div>

The current Fn struct only stores type and attribute info. Perhaps something like @hasDecl / @hasField for function/param names.

---

## [\`inline for\` behaves unexpectedly when calling a function](https://ziggit.dev/t/inline-for-behaves-unexpectedly-when-calling-a-function/16326)

<div class="topic-metadata">

**Author:** [@Shrimo](https://ziggit.dev/u/Shrimo)\
**Replies:** 9\
**Last updated:** [June 25, 2026, 6:25am UTC](https://ziggit.dev/t/inline-for-behaves-unexpectedly-when-calling-a-function/16326 "2026-06-25T06:25:19Z")

</div>

fn is\_even(n: usize) bool { return (n % 2 == 0); } pub fn main() void { const numbers = .{ 1, 2, 3, 4, 5, 6 }; inline for (numbers) |n| if (n % 2 == 0) @compileLog(n); // 2, 4, 6 inline for (nu…

---

## [Arena comptime lock](https://ziggit.dev/t/arena-comptime-lock/16311)

<div class="topic-metadata">

**Author:** [@mg979](https://ziggit.dev/u/mg979)\
**Replies:** 4\
**Last updated:** [June 23, 2026, 5:35pm UTC](https://ziggit.dev/t/arena-comptime-lock/16311 "2026-06-23T17:35:58Z")

</div>

I’m using several arenas and I lock them when I use them, so that I don’t accidentally reset them further down the stack, and can only get/reset them in one scope: ▶ code But I’m wondering if these busy checks can be mov…

---

## [Reifying optional type](https://ziggit.dev/t/reifying-optional-type/16217)

<div class="topic-metadata">

**Author:** [@alcn](https://ziggit.dev/u/alcn)\
**Replies:** 3\
**Last updated:** [June 17, 2026, 9:57am UTC](https://ziggit.dev/t/reifying-optional-type/16217 "2026-06-17T09:57:32Z")

</div>

Hello, I would like to reify an optional type at comptime. More specifically, if I have a type T, I would like to create the type ?T. I could do this in 0.15.2 with @Type, but I’m using 0.16.0. Thanks

---

## [Double xor optimisation](https://ziggit.dev/t/double-xor-optimisation/16148)

<div class="topic-metadata">

**Author:** [@username1](https://ziggit.dev/u/username1)\
**Replies:** 5\
**Last updated:** [June 13, 2026, 6:31pm UTC](https://ziggit.dev/t/double-xor-optimisation/16148 "2026-06-13T18:31:59Z")

</div>

I'm new to programming with zig and I've tried to write a small xor cipher with a static key on linux. Here's my code : const std = @import("std"); const write = std.os.linux.write; const key = "abc"; const secret = x…

---

## [Export a thread-local variable as a weak symbol](https://ziggit.dev/t/export-a-thread-local-variable-as-a-weak-symbol/16149)

<div class="topic-metadata">

**Author:** [@cancername](https://ziggit.dev/u/cancername)\
**Replies:** 2\
**Last updated:** [June 13, 2026, 5:49pm UTC](https://ziggit.dev/t/export-a-thread-local-variable-as-a-weak-symbol/16149 "2026-06-13T17:49:18Z")

</div>

Hi! I’m trying to export a thread-local variable as a weak symbol. In GNU C, this can be accomplished like so: #include \<stdint.h\> \_\_thread uint32\_t \_\_attribute\_\_((weak)) weak\_threadlocal = 1; $ zig build-obj weakthr…

---

## [Craeting a @Struct, @Union is it possible to add const fields inside the namespace](https://ziggit.dev/t/craeting-a-struct-union-is-it-possible-to-add-const-fields-inside-the-namespace/15995)

<div class="topic-metadata">

**Author:** [@SillyProgramming](https://ziggit.dev/u/SillyProgramming)\
**Replies:** 1\
**Last updated:** [June 7, 2026, 3:13pm UTC](https://ziggit.dev/t/craeting-a-struct-union-is-it-possible-to-add-const-fields-inside-the-namespace/15995 "2026-06-07T15:13:23Z")

</div>

I want to generate a struct at comptime with a const field inside the namespace. The expected result would be like this. const x = struct { const desc = ""; } Or this is not permitted for the same reason function …

---

## [Optimize runtime checks away with double compilation](https://ziggit.dev/t/optimize-runtime-checks-away-with-double-compilation/15635)

<div class="topic-metadata">

**Author:** [@PauSolerValades](https://ziggit.dev/u/PauSolerValades)\
**Replies:** 17\
**Last updated:** [June 6, 2026, 2:28pm UTC](https://ziggit.dev/t/optimize-runtime-checks-away-with-double-compilation/15635 "2026-06-06T14:28:12Z")

</div>

Hello :)) I am building a Discrete-Event simulation of a social network (cannot share the code to it yet..), and this idea came to me. To schedule the time between events, I use runtime dynamic dispatching reading from …

---

## [Functions inside comptime enum](https://ziggit.dev/t/functions-inside-comptime-enum/15843)

<div class="topic-metadata">

**Author:** [@snake](https://ziggit.dev/u/snake)\
**Replies:** 2\
**Last updated:** [June 1, 2026, 7:47am UTC](https://ziggit.dev/t/functions-inside-comptime-enum/15843 "2026-06-01T07:47:40Z")

</div>

I want to create enums at comptime, using the @Enum keyword, which have behavior. Specifically jsonParse and jsonStringify. Is there a way to define a function inside the namespace of a generated type?

---

## [Zebra - A simple, fast, all-in-one config loader for Zig](https://ziggit.dev/t/zebra-a-simple-fast-all-in-one-config-loader-for-zig/14705)

<div class="topic-metadata">

**Author:** [@omkar-foss](https://ziggit.dev/u/omkar-foss)\
**Replies:** 2\
**Last updated:** [May 27, 2026, 1:54pm UTC](https://ziggit.dev/t/zebra-a-simple-fast-all-in-one-config-loader-for-zig/14705 "2026-05-27T13:54:28Z")

</div>

Hello dear Zig buddies, I’ve recently built this library called Zebra: GitHub - omkar-foss/zebra: A simple, fast, all-in-one config loader for Zig. · GitHub It’s a simple, fast, all-in-one config loader for Zig project…

---

## [Translating enums from C](https://ziggit.dev/t/translating-enums-from-c/15684)

<div class="topic-metadata">

**Author:** [@MrWizard343](https://ziggit.dev/u/MrWizard343)\
**Replies:** 3\
**Last updated:** [May 24, 2026, 5:34am UTC](https://ziggit.dev/t/translating-enums-from-c/15684 "2026-05-24T05:34:13Z")

</div>

I’m having some trouble updating a function to construct enums from C libraries. I’d like to automatically translate the keyboard event structure from SDL3. fn buildEnumFromC(comptime import: anytype, comptime prefix: \[…

---

## [REFramework wrapper in Zig](https://ziggit.dev/t/reframework-wrapper-in-zig/15190)

<div class="topic-metadata">

**Author:** [@korke](https://ziggit.dev/u/korke)\
**Replies:** 1\
**Last updated:** [May 21, 2026, 12:26am UTC](https://ziggit.dev/t/reframework-wrapper-in-zig/15190 "2026-05-21T00:26:57Z")

</div>

REFramework is a modding framework, scripting platform, and modding tool for RE Engine games(copy pasted from their description). Some famous titles made using RE Engine: Resident Evil Requiem, Resident Evil 7, Resident …

[Next page](https://ziggit.dev/tag/comptime/9.md?match_all_tags=true&page=1&tags%5B%5D=comptime)
