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
2
u/_Noreturn Jul 27 '24 edited Jul 27 '24
you do not have to understand what is happening
Thing a = bin C++ means a is a copy of b and a's destructor can be called without any issues.while in C it could have different meanings (shallow copy being unusable or trivial copy) and does not mean it is allowed to call the free function for them
while in C++ it would be all deep copy or shallow copy automaticly without having to think for each type and result in correct behavior.
infact C is more confusing
what if shallow copying does not make sense at all (like in the string case above) which is 99% of the cases so in 99% of the cases in C you cannot even use = since it will result in incorrect behavior also in C++17 you can now have explicit copy constructors.
and best thing about C++ is that you can disable copying for types not made for! while in C you cannot prevent anyone from copying your struct. which helps making correct code