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
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Compile-time function execution is great, but what if:
9
9
2. You don't want to use evil C macros.
10
10
3. You want generic data structures that work for all types.
11
11
12
-
The below data structure showcase programs get optimized away at compile time by GCC and Clang, such that only the `printf()` at the end of `main()` is left:
12
+
The below data structure showcase programs get optimized away at compile time by Clang and GCC, such that only the `printf()` at the end of `main()` is left:
13
13
```nasm
14
14
main:
15
15
push rax
@@ -29,13 +29,13 @@ 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
-
[Link-time optimization](https://en.wikipedia.org/wiki/Interprocedural_optimization) with `-flto` should allow GCC and Clang to perform these optimizations even when the code is split across several object files.
32
+
[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.
33
33
34
34
# Generic Stack
35
35
36
-
GCC requires `-O1`, while Clang requires `-O2`.
36
+
Clang and GCC require `-O1`.
37
37
38
-
Copy of the code on [Compiler Explorer](https://godbolt.org/z/sGos8zvzE):
38
+
Copy of the code on [Compiler Explorer](https://godbolt.org/z/r77c6hf8d):
0 commit comments