Re:Parse, don’t type-check
by inetknght on Thursday November 26, 2020 @08:35PM
(#25224876)
> 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.
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
[2] https://gcc.godbolt.org/z/cGe39z
[3] https://gcc.godbolt.org/z/orb1s8