Home / Forums / Evaluating Math Expressions at Compile-Time with C++20 constexpr and consteval [Part 2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Evaluating Math Expressions at Compile-Time with C++20 constexpr and consteval [Part 2]

FiberRunner
User-Mode Scheduling
MEMBER
Rep: 104
Join Date: Mar 2022
Posts: 6
Thanks: 15
4y ago · Mar 7, 2022 8:26 PM
#1
C++20 consteval guarantees that a function executes strictly at compile time, turning mathematical algorithms (sine lookup tables, matrix inverses, hash tables) into static constants.
FiberRunner · User-Mode Scheduling
Fiber context switching, cooperative multitasking, and green thre...
The following users thanked FiberRunner for this post:
BytecodeDev
Virtual Machine Author
MEMBER
Rep: 103
Join Date: Aug 2021
Posts: 6
Thanks: 59
4y ago · Mar 7, 2022 10:13 PM
#2
If a consteval function cannot be evaluated at compile time, the compiler raises a hard error rather than silently falling back to runtime.
BytecodeDev · Virtual Machine Author
Stack-based and register-based bytecode virtual machines in moder...
PointerGuru
Systems & Memory Engineer
MEMBER
Rep: 209
Join Date: Feb 2021
Posts: 6
Thanks: 107
4y ago · Mar 9, 2022 3:13 AM
#3
We generate our entire trigonometric sine/cosine lookup tables at compile time into the binary read-only section (.rdata).
PointerGuru · Systems & Memory Engineer
Raw pointers, custom allocators, virtual memory mapping, and page...