4 ms·
> A big part of C++'s culture was that we don't need to write unsafe C code unless we really must In C++ you don't have to drop down to "unsafe C code" to lose
by jjnoakes 8y ago
> A big part of C++'s culture was that we don't need to write unsafe C code unless we really must
In C++ you don't have to drop down to "unsafe C code" to lose lots of safety guarantees (like data races, iterator invalidation, danging pointers, use-after-free, use-after-move, etc)...
- pjmlp 8y agoTrue, but you have missed the part that makes C++ safer than C. - User defined types with invariants - templates, const, constexpr and if constexpr instead of macros - proper string types - proper vector types - type safe enumerations - many implicit conversions in C are compiler errors in C++ - RAII - contracts - generic data structures The iterator invalidation is easy to find out in compilers like Visual C++, their STL implementation can be customized to validate iterator invariants. The danging pointers, use-after-free, use-after-move mentioned by you are the purpose of this proposal. I was an early C++ adopter in 1992, LLVM rejuvenated language research in 2003, DirectX and Metal shaders are a C++ dialect, AUTOSAR has migrated from C to C++14 only two years ago, NVidia GPUs since Volta (2017) are now being designed to run C++ code efficiently. A time frame of about 30 years for C++ to become widespread as it is. I am all for Rust or similar language to replace C++ and do away with C copy-paste culture, but I am not throwing away all my code just because. So yeah, it isn't perfect, but it surely is way better than plain C coding and the community does try to promote not doing C in C++. CppCon 2015: Kate Gregory “Stop Teaching C" https://www.youtube.com/watch?v=YnWhqhNdYyk https://www.youtube.com/watch?v=YnWhqhNdYyk
- jjnoakes 8y ago> True, but you have missed the part that makes C++ safer than C. Of course C++ is safer than C. I was just responding to what I quoted, which unfairly lumps "unsafe" and "C" in the same turn of phrase, implying that avoiding C-like code avoids unsafety as well.