Hacker News new | ask | show | jobs
by afiori 336 days ago
Is dereferencing an arbitrary integer cast to pointer UB on any platform? I would expect that it is system dependent but mostly not C-style UB
1 comments

Dereferencing an arbitrary integer cast to a pointer means you are dereferencing an arbitrary memory location, which includes memory that is outside the purview of the C abstract machine model, say the return address of the function. That means the effect of that operation can't be meaningfully constrained, and the only option for that is UB.

(Integer-to-pointer conversions beg the question of pointer provenance, which is a long, complicated topic that is still not fully solved, but does go to show that UB is actually a lot more complicated than most people expect.)