Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As kragen already posted, you can cast from const-pointer to non-const directly.

Not allowing a cast from integer to pointer is the point of having pointers as capabilities in the first place.

Central in that idea of capabilities is that you can only narrow privileges, never widen them. An intptr_t would in-effect be a capability narrowed to be used only for hashing and comparison, with the right for reading and writing through it stripped away.

BTW, if you would store the uintptr_t then it would lose its notion of being a pointer, and Fil-C's garbage collector would not be able to trace it.

The C standard allows casts both ways, but the [u]intptr_t types are optional. However, C on hardware capability architectures' (CHERI, Elbrus, I dunno about AS/400) tend to make the type available anyway because the one-way cast is so common in real-world code.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: