I want to use constexpr
instead of #define
s wherever possible, for type safety and namespace features.
Unfortunately, I get this error: 'reinterpret_cast<SPI_TypeDef*>(1073756160)' is not a constant expression
when trying.
#include <stm32f0xx.h> // #defines SPI2 as pointer to a struct of volatile unsigned ints
constexpr auto myPort = SPI2;
I'm not looking for an explanation of why reinterperet_cast
cannot be used in a constexpr
.
What is the modern C++ way to have a constexpr pointer to some memory mapped hardware?
One reason for this is to use these constexpr
values in templated code.