Better late than never: I am trying to update my code bases to recent C++ standards, right now trying to really understand the intentions of the constexpr syntax feature.
However, I am struggling with this: In one of my microcontroller projects (plain C++ without some of the higher level std features), I have a configuration header that contains a rather large list of #define statements that allow the non-developer user to configure certain constant values (most of the time device-dependant parameters). Example:
#define SERIAL_DEVICE_XY_BAUD_RATE (9600)
#define MAX_SENSORDATA_BUFFER_LENGTH (250)
It seems to me, that this would be a great option to migrate this to constexpr definitions (biggest point for me would be namespaces and type safety for these values).
Now my question: While I want to keep the seperate header file with the configuration constants, how does one use constexpr without duplicating memory allocation? As I understand it, migrating to constexpr like:
constexpr unsigned int device1_baud_rate = 115200;
would give a completely isolated (new) variable with appropriate memory allocated. When using this (like right now with the macro definitions) in the constructor of a class somewhere else in the programm, it gets copied to the member variable, leaving me with two variable allocations instead of one.
I guess I'm missing kind of a concept that makes uses of such constexpr values directly, could anyone point me in the right direction for this usecase? Thanks!