|
|
|
|
|
by wwright
2384 days ago
|
|
Not only can you cast away anything, but: - casting away types unsafely is required for many common patterns in C, including any form of runtime polymorphism - basically anything involving numerics has a good chance of happily casting for you without asking you or telling you |
|
Which patterns? I'm thinking of stuff like the Berkeley Sockets API, which you can absolutely implement safely.
re numerics: fortunately, that's 100% amenable to static analysis (see -Wconversion, -Wsign-conversion in gcc/clang and coverity's warnings about potentially unsafe casts - e.g. promoting an int to a long is always safe, but an int to a float not necessarily) and follows very straightforward rules.