constexpr is a C23 construct for declarations and compound literals whose values are fixed and known during compilation. Unlike a merely const-qualified object, a constexpr object is guaranteed not to change and supplies a compile-time constant. section 5.6.1 section 5.6.5
A named compile-time constant
constexpr double π = 3.141'592'653'589'793'238'46; declares a read-only double whose value is fixed for the whole compilation. The initializer must fit the declared type exactly: constexpr unsigned πflat = 3.141'592'653'589'793'238'46; is an error because conversion loses significant digits. section 5.6.5
Use constexpr to satisfy compile-time constant requirements:
- Declare named constants for values that must be known during compilation, including values used in file-scope initializers. section 5.6.1 section 5.6.5
- Use constexpr objects in integer constant expressions; unlike ordinary const objects, they may participate as evaluated operands. section 5.6.2
- Apply constexpr to compound literals, including arrays; array elements receive their indicated values and remaining character positions are filled with zeros. section 5.6.5
- Treat exact type fit as a validity rule: a conversion that changes the initializer's value is rejected at the declaration. section 5.6.5
# define CORVID_NAMES /**/ \
(constexpr char[8][corvid_num]){ \
[chough] = "chough", \
[raven] = "raven", \
[magpie] = "magpie", \
[jay] = "jay", \
}
Inspect a constexpr compound literal representing an array of fixed-size character arrays, with designated entries for corvid names. section 5.6.5


