Answer the question
In order to leave comments, you need to log in
C++11 how to make the calculation of the address in the pointer to the structure happen at compile time?
There is a code sample that successfully builds on GCC up to 6.1, but does not build on GCC 6.3 and does not build on any version of Clang.
constexpr int * const t = reinterpret_cast<int *>(0x40000);
template <int addr>
class C {
public:
struct gpio_t {
int test;
};
static constexpr volatile gpio_t * const regs =
reinterpret_cast<volatile gpio_t *>(addr);
};
int main() {
C<0x40000000>::regs->test = 5;
}
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then all these perversions are only to work with an arbitrary address in memory, as with a structure field. In this regard, the question is why not just do this:
struct gpio_t {
int test;
};
#define TEST_1 reinterpret_cast<volatile gpio_t *> (0x12345678)
int main() {
TEST_1->test = 5;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question