say i have some hardware mmio structure, that has two fields for a pointer, hi and lo
is it defined behavior in c to:
cast my pointer to uintptr_t
split it and assign across those two fields
and later in another function:
bitwise join the two fields in a uintptr_t
cast the result back to the original pointer type that i've allocated beforehand
since the value representation should be the same after rebuilding the uintptr, and uintptr is defined as surviving roundtrips, i think it's all good?
0 Boosts
0 Likes
@uecker i have heard the same and it’s why i asked in the first place
TS6010 looked promising, currently c23 seems to just say “the result is implementation defined” for the conversion both ways, which for what i’m doing (osdev, kernel) that’s probably good enough i think
and it also seems to mean that casting an address like char *ptr = (char *)0xE0000 is also IB, which eases me a bit w.r.t to the bits of acpi where i had to probe specific memory ranges
@navi Yes, these are the things which uintptr is for. (I have heard the absurd claim that because the standard only says that the pointer converted back compares equal, it is not guaranteed that you can actually use it. TS 6010 would have made it clearly legal.)