Hacker News new | past | comments | ask | show | jobs | submit login

I didn't realize that distinction, so it's good to know. Still, as I originally assumed, I confirmed that gcc with `-Wall -Werror -std=c99` flags won't compile an initialization of a "struct seagull * " with a value of type "struct enemy * ", or passing a mismatch of those types to a function. If those would be the main reasons to use C++, I'd personally rather just use C with extra checks. But to be fair, maybe that's because I'm not very comfortable with C++, to the point that I didn't notice it checks pointer types.



Yes. In C, conversion between object pointer types requires a cast, but conversion from void pointer to object pointer does not; in C++, both conversions require a cast.

Conversion from void pointer to object pointer would be very a bit annoying to warn about in general, as it's so commonly used in C. And if you always use casts, that also hide other types of error (see, e.g., http://c-faq.com/malloc/mallocnocast.html).

I'm sure there are compilers (and possibly gcc/clang can do it, too...) that will warn you about this stuff without needing you to switch to C++.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: