As already mentioned by @fanl, const does change the default binding to global variables in C ++ and does not allow you to define a variable without initialization.
But there are better ways to get an external connection than removing const . The use of reserved arrays in the header file associated with Chris is also very fragile. I would say that this code leaves a lot of room for improvement - do not emulate it.
In addition, these variables cannot be defined (which the compiler and linker will call to select an address), they are always accessed through pointers, and the address is fixed in accordance with the memory card.
For headers intended solely for use with C ++, this is how I do it (the memory card matches the TI Stellaris chip).
It looks more complicated, but the optimizing compiler reduces it to a single access statement. And the address offsets are encoded, regardless of the order and filling of the fields inside the structure, so it is much less fragile and easier to check in comparison with the data table.
template<uintptr_t extent> struct memory_mapped_peripheral { char data[extent]; volatile uint32_t* offset( uintptr_t off ) { return reinterpret_cast<volatile uint32_t*>(data+off); } volatile const uint32_t* offset( uintptr_t off ) const { return reinterpret_cast<volatile const uint32_t*>(data+off); } }; struct LM3S_SYSTICK : private memory_mapped_peripheral<0x1000> { volatile uint32_t& CTRL (void) { return offset(0x010)[0]; } volatile uint32_t& RELOAD (void) { return offset(0x014)[0]; } volatile uint32_t& CURRENT(void) { return offset(0x018)[0]; } }* const SYSTICK = reinterpret_cast<LM3S_SYSTICK*>(0xE000E000); struct LM3S_NVIC : private memory_mapped_peripheral<0x1000> { volatile uint32_t& EN (uintptr_t i) { return offset(0x100)[i]; } volatile uint32_t& DIS (uintptr_t i) { return offset(0x180)[i]; } volatile uint32_t& PEND (uintptr_t i) { return offset(0x200)[i]; } volatile uint32_t& UNPEND(uintptr_t i) { return offset(0x280)[i]; } volatile const uint32_t& ACTIVE(uintptr_t i) const { return offset(0x300)[i]; } volatile uint32_t& PRI (uintptr_t i) { return offset(0x400)[i]; } volatile uint32_t& SWTRIG(void) { return offset(0xF00)[0]; } }* const NVIC = reinterpret_cast<LM3S_NVIC*>(0xE000E000);
source share