You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2025-11-30-comptime-c-functions.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,18 +29,19 @@ Here is how it is achieved in C:
29
29
30
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.
31
31
32
-
The only legitimate use-case I can think of for this technique is generating lookup tables at compile-time.
32
+
The only legitimate use-case I can think of for this technique is generating lookup tables at compile-time, as functions like `sin()` also get optimized away.
33
33
34
34
[Link-time optimization](https://en.wikipedia.org/wiki/Interprocedural_optimization) with `-flto` should allow Clang and GCC to perform these optimizations even when the code is split across several object files.
35
35
36
36
# Generic Stack
37
37
38
38
Clang and GCC require `-O1`.
39
39
40
-
Copy of the code on [Compiler Explorer](https://godbolt.org/z/r77c6hf8d):
40
+
Copy of the code on [Compiler Explorer](https://godbolt.org/z/Y86szvfeG):
0 commit comments