Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The two languages really should be used as different tools as although there is obviously significant use-case overlap, each excels at its own niche. C++ is quite beyond C with classes. Personally, I think C++ should continue to evolve far away from C (though as of C++20 we now have C99's designated initializers). C is "perfect" for what it is, dare I say it. C++ can incorporate things we've learned from other languages like Rust's memory safety and be better for it. Though to be fully honest I haven't totally worked through the revised memory model of C++20 and it would be great if someone could shed some light on that.


> though as of C++20 we now have C99's designated initializers

C++20 only supports a thin imitation of C99's designated initializers. In C99 you can a) mix definition forms (designated and non-designated), b) define members out of order, and c) override earlier definitions. C++20 doesn't support any of these. I've often relied on a and c in initializer macros that provide default, non-0 values that can be overridden (using vararg parameters) by the user, but many might see that as unclean. The lack of b, however, significantly diminishes the value of designated initializers: by reordering struct members you invalidate all uses of designated initializers for that type in C++20, which means they're useless to minimize the burden of refactoring.

Also, C++20 doesn't permit designated array initializers, which I've found very useful for arrays that map, e.g., enums to strings.




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

Search: