I had a little function which converted virtual memory address to physical on a 32-bit architecture:
uint32_t VIRTBASE;
uint32_t getPhysForVirt(void* virt) {
uint32_t offset = (uint8_t*)virt - VIRTBASE;
return PHYSBASE + offset;
}
It compiled and worked without any single issue in last 10+ years.
I've changed the compiler to build the repo for newer architectures (now with 64bit support for the first time).
Compilation fails stating
invalid conversion from ‘uint8_t*’ {aka ‘unsigned char*’} to ‘uint32_t’ {aka ‘unsigned int’} [-fpermissive]
Now, I understand the message, but I'm not sure about the necessary steps to make this compiling without errors.
I'm only sure in that I don't want to enable -fpermissive.
You use the wrong types. C language has special types for casting pointers to integral values.
uintptr_t VIRTBASE;
uintptr_t getPhysForVirt(const void * restrict virt) {
ptrdiff_t offset = (uintptr_t)virt - VIRTBASE;
return PHYSBASE + offset;
}
If the rest of code is written the way as this function was - you have plenty work for Christmas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With