Pointers Are Complicated III, or: Pointer-integer casts exposed
IMHO, casts from integer to pointer should have been deprecated in C (and derivative languages) a long time ago.<p>Not only do they encourage unsafe practices, being forbidden in most C&#x2F;C++ style guides.<p>They can also wreak havoc with any hardware or software-hardening that puts non-address bits in pointers. For instance, ARM PAC has been in Apple&#x27;s CPUs for years now and support is mandatory in ARM v8.3 and up. Intel and AMD have also had experimental extensions that use those bits, and new ones are on the way.<p>When an integer is cast to pointer in those schemes, the pointer can become invalid.
Therefore, an integer cast to a pointer type should <i>always</i> result in an invalid pointer, IMHO.<p>Integers are sometimes used to set alignment. I&#x27;d suggest that the macros in CHERI C be added to &lt;stdalign.h&gt;: <i>align_up</i>, <i>align_down</i> and <i>is_aligned</i>. Those can be expressed in normal C without having to cast an integer to pointer, or use faster expressions depending on the platform.