# Static comptime variable? (preserve state between two comptime function calls)

**URL:** <https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691>\
**Category:** Help\
**Tags:** comptime\
**Created:** [September 23, 2026, 1:12pm UTC](https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691 "2026-09-23T13:12:14Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![npc1054657282](https://ziggit.dev/user_avatar/ziggit.dev/npc1054657282/32/5790_2.png) [@npc1054657282](https://ziggit.dev/u/npc1054657282)\
**Post date:** [September 23, 2026, 3:55pm UTC](https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691/8 "2026-09-23T15:55:10Z")

</div>

> [@psznm](#):
>
> Well, the post talks about capturing comptime var reference at runtime.

There’s also one more rule that makes global comptime state impossible.

> [@Comptime-Mutable Memory Changes](https://ziggit.dev/t/comptime-mutable-memory-changes/3702/1):
>
> The second rule is that a pointer to a `comptime var` cannot be contained within the resolved value of a container-level `const` or `var` declaration. Intuitively, the `comptime var` is not allowed to “leak out” of the declaration that created it.

This does indeed lead to many comptime use cases not being met, but the upside is that all compilation units are independent of order.

> [@Comptime-Mutable Memory Changes](https://ziggit.dev/t/comptime-mutable-memory-changes/3702/1):
>
> Incremental compilation relies on the fact that global declarations are largely independent of one another, and their interdependencies can be easily modeled (for instance, one global declaration might depend on the resolved value of another). We also depend on the fact that the order of analysis of different declarations is (aside from some awkward edge cases, which eventually will either be ironed out or defined as implementation-defined behavior) unobservable. Unfortunately, global comptime state breaks both of these promises. Loads and stores of this state depend entirely on analysis order, and re-analyzing a declaration may mutate global state in ways which would not happen without incremental compilation. In short, the previous behavior was **completely incompatible with incremental compilation**.

---

_[View the full topic](https://ziggit.dev/t/static-comptime-variable-preserve-state-between-two-comptime-function-calls/17691)._
