reinterpret_cast<volatile uint8_t*>(37)' is not a constant expression

一笑奈何 提交于 2019-12-11 04:26:10

问题


gcc fails to compile the code below, while clang compiles ok. I have no control on the macro PORTB, as it is in a 3rd party library (avr).

Is it a gcc bug? How can I work around it in gcc? As a workaround is somehow possible to create a pre-processor macro which extracts the numerical value from PORTB?

Note this question is similar, but not identical to my previous question. It is also different from this question, where the developer has the flexibility to change the rhs of the assignment, thus avoiding the reinterpret_cast.

#include <iostream>
#include <cstdint>

#define PORTB (*(volatile uint8_t *)((0x05) + 0x20))

struct PortB {
    static const uintptr_t port = reinterpret_cast<uintptr_t>(&PORTB);
};

int main() {
    std::cout << PortB::port << "\n";
    return 0;
}

来源:https://stackoverflow.com/questions/54174694/reinterpret-castvolatile-uint8-t37-is-not-a-constant-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!