Skip to content

Commit edb0213

Browse files
authored
Update 2025-11-30-comptime-c-functions.md
1 parent 0661b82 commit edb0213

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

_posts/2025-11-30-comptime-c-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Here is how it is achieved in C:
2727
- All operations become statically analyzable, reducing to constants.
2828
- `assert()` calls get eliminated when conditions are provably true.
2929

30-
This optimization requires stack-allocated buffers with constant addresses. Heap allocation breaks the optimization, because the compiler can't trace memory operations through dynamic allocations.
30+
It's not actually "stack vs heap" that matters; what matters is whether the compiler can treat the buffer as a non-escaping, fully analyzable region of memory. Stack allocation makes that easy. Heap allocation only works in very simple cases where the pointer never escapes and all memory operations can be folded away.
3131

3232
The only legitimate use-case I can think of for this technique is generating lookup tables at compile-time, since functions like `sin()` *also* successfully get optimized away.
3333

0 commit comments

Comments
 (0)