C++: Difference between revisions

Line 463: Line 463:
===const===
===const===
For variables:
For variables:
# Use <code>constexpr</code> for values initialized at compile time and won't change at runtime. Most of the time, this is what you want for hardcoded compile time parameters.
# Use <code>const</code> for values initialized at runtime and won't change.
# Use <code>const</code> for values initialized at runtime and won't change.
# Use <code>constexpr</code> for values initialized at compile time and won't change at runtime.
# Use <code>constinit</code> for values initialized at compile time and may change at runtime. I haven't found a use case for this yet.
# Use <code>constinit</code> for values initialized at compile time and may change at runtime.


For functions:
For functions: