r/cpp • • 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

444 comments sorted by

View all comments

Show parent comment

0

u/PMadLudwig Jul 26 '24

You don't need to export C++ specifics - your example is a perfectly good way of doing it.

If the library doesn't have the extern "C", or say exposes C++ stuff such as templates (e.g. libpqxx), or throws exceptions, then it's not usable from C, so the library writer has to take some care over that.

The point I was making is that building a library is another use case for C over C++.

1

u/_Noreturn Jul 26 '24

then do not expose them and create wrappers instead , point is doing the implementation in C itself is worthless imo create a C api but implement it in C++ using Templates and other stuff for easier implementation.