I have an array of unsigned integers that should store pointers to data and functions, as well as some data. On the device I'm working with, the sizeof pointer is the same as sizeof unsigned int. How can I overlay a function pointer in an unsigned int? I know that this makes the code not portable, but it is a microcontroller. I tried this:
stackPtr[4] = reinterpret_cast<unsigned int>(task_ptr);
but it gives me the error "invalid type conversion"
Dropping it to a void pointer and then to int is confusing.
stackPtr[4] = reinterpret_cast<unsigned int>(static_cast<void *> (task_ptr));
Is there a clean way to do this?
Edit - task_ptr - pointer to the function void task_ptr(void)
Barmaraโs love answers, removes my tolerance. Also, the void pointer array actually makes more sense than Unsigned Ints. Thanks, Barmar and isaach1000.
EDIT 2: Got this, my compiler thinks of a large memory model, so it uses the 32-bit pointers, not the 16-bit that I expected (small microns with a total memory of 17 KB).
source share