. GNU (g++, ld):
constexpr, . :
⋮
SECTIONS
{
GPIO 0x48000000 (NOLOAD) : { *(.GPIO) }
⋮
.GPIO 0x48000400. POD, . POD gpio_t : mode. constexpr. , , . . , , .
struct gpio_t {
volatile std::uint32_t mode;
};
__attribute__ ((section (".GPIO"))) gpio_t Gpio = {0};
static constexpr gpio_t *port {&Gpio};
static constexpr void init () {
port->mode = 42u;
};
void main {
init ();
⋮
};
Note: constexprC's idiom in C style does not work, because it is reinterpret_cast<>not suitable for creating pointers constexpr(see C ++ 14 is invalid ). The following errors :
constexpr gpio_t *port {(gpio_t *) 0x48000400};
source
share