Safer Casting in C – With Zero Runtime Cost – Making Casts Visible, Auditable(medium.com)
medium.com
Safer Casting in C – With Zero Runtime Cost – Making Casts Visible, Auditable
https://medium.com/@yair.lenga/safer-casting-in-c-with-zero-runtime-cost-making-casts-visible-auditable-and-harder-to-misuse-331b3a3a8090
2 comments
I ran into a few subtle bugs around casts in C—mostly pointer precedence and intent not being obvious in reviews.
Things like (long *)buf + 1 are easy to misread at a glance.
I tried making casts more explicit with small macros (CAST_PTR1, etc.) and adding some compile-time checks.
Curious how others deal with this—warnings, conventions, or just careful review?
Things like (long *)buf + 1 are easy to misread at a glance.
I tried making casts more explicit with small macros (CAST_PTR1, etc.) and adding some compile-time checks.
Curious how others deal with this—warnings, conventions, or just careful review?
I think these cast problems are ultimately something that the compiler can and should catch. And a stronger type enforcement system would be nice, but also I use C so i don't have to deal with rust's nonsense