EMBEDDED TOOLKIT
SYSTEMS R&D // DEV_TOOLS SUITE
Tools (65)
c constexpr tester
SYSTEM ONLINE
Definition: constexpr (C++11)
Meaning in English
I COULD calculate this at compile time, if you give me constant data. If you give me dynamic variables, I will act as a normal function/variable and calculate it on the fly.
Time Dependency (Execution)
Optionally Compile-Time, otherwise Run-Time
Memory Position (ROM/RAM)
Yes, if used in a constant context. Values are placed as hardcoded Assembly.
Example C++ Code
📖 C++ Meta-Programming for Embedded
Using C++ (instead of pure C) in microcontrollers was once infamous (mainly due to alleged memory overhead of abstractions). The modern C++11 standard, and especially C++20, changes the game by introducing the aforementioned keywords.
- Thanks to
constevalyou can write giant mathematical calculators with FOR loops that the compiler will resolve in the background on your PC, and flash into the microcontroller only a single, computed constant number. - Whenever possible for global constants (e.g. prescalers) use in C++
constexprinstead of old-fashioned C preprocessor macros#define, because constexpr is strongly typed and GDB debugger friendly!