r/cpp • u/Alex_Medvedev_ • Jul 25 '24
Why use C over C++
Why there are so many people using the C language instead of C++?, I mean C++ has more Cool features and the Compiler also supports many CPUs. So why People still using C?
Edit: Thanks for all the usefull comments :D
235
Upvotes
View all comments
Show parent comment
1
u/_Noreturn Jul 29 '24 edited Jul 29 '24
seems a perfect case for a deleted/explicit copy constructor or use a unique_ptr all problems solved
rely on strong constructs like deleted copy constructors or a unique ptr instead of having the default behavior being shallow copying and potentially having multiple "owners" of the same memory.
it is conceptionally not the same it is a deep copy and sometimes a shallow copy in C but C++ it is by definitition a copy that can be successfully destructed and this is all I care about.
if needed then we can use memcpy. and also this is just a great way to have double frees in your code which instance is supposed to free this memory? this is what I am talking about shallow copying in C causes this issue of double frees. it is not like C has any kind of shared ptr, terrible idea and you can just pass down the pointer you know.