Re:Parse, don’t type-check
by moonchild on Thursday November 26, 2020 @06:28PM
(#25224298)
I don't quite follow. C will also prevent you from mixing up disparate pointer types; and c++ has no protection against void pointers.
[ Parent
| on HN ]
> C will also prevent you from mixing up disparate pointer types
No it won't. In C++ it's a compile error [0]. In C it's just a warning [1].
> c++ has no protection against void pointers
You're somewhat correct but the answer is a lot more nuanced (because void* is very nuanced). Again, C++ will complain unless you do it "right" [2] while C is ... willing to let you blow your leg off [3]. However the definition of "right" is still just as dangerous as C's because all type information was lost in the void and it's up to the programmer to get it right -- and programmers are notoriously buggy.
[0] https://gcc.godbolt.org/z/166ns8
[1] https://gcc.godbolt.org/z/vEnajj