We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
void function(void) { printf("test"); } const uint16_t addr = (uint16_t)function;
Why MDK(ARM) report an error: initializer element is not a compile-time constant ?
Because it isn't one.
But there is really only one "function" in my project!
I tried to compile this code in a minimal project, and I changed the function name and variable name, the problem remains;
But
const uint32_t addr = (uint32_t)function;
can be compiled correctly!
Maybe because it makes not really sense to store the (non constant) address of a function in a 16 or 32 bit integer variable?
My MCU flash is only 64K. I want to create a very large list of callback functions. If I use 32-bit address, obviously the upper 16 bits are meaningless.