News for hackers. Stuff that matters.
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.
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.

[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

Re:Parse, don’t type-check by int_19h on Saturday November 28, 2020 @08:54PM (#25242302)
Using extern "C" doesn't change the C++ rules for implicit pointer conversions, though.