3 ms·
it is just you. why would anyone go back to C from C++? if you want to write C in C++, you can do that, with the advantages of stronger type checking.
by zabzonk 3y ago
it is just you. why would anyone go back to C from C++? if you want to write C in C++, you can do that, with the advantages of stronger type checking.
- SV_BubbleTime 3y agoYou can use the C syntax in C++. But you are not using C, your compiler is still C++.
- zabzonk 3y agoyes the compiler is the same (for example gcc or msc) but why would you care?
- SV_BubbleTime 3y agoFirst off… GCC is not the compiler. It is the toolchain collection. Second, no, g++ does act identical to the c compiler component of GCC.
- burstmode 3y agoMany people, Especially sice C++ has become a playfield for CS language theorists, who invent more and more overcomplicated language "features" with little to no practical use.
- pjmlp 3y agoThat is still Haskell. Getting features into WG21 still requires some effort to get them through, regardless of what people in the outside think, and yeah I do agree it could get some more direction. C++ may seem to get everything dumpped into it, however any language nerd that feels like diving into what the history of languages with similar age (Python, Perl, Ada, C#, Java, F#, OCaml,...) have across all their versions, standard library, main interpreter/compilers, .... will find out those aren't much better either.
- zabzonk 3y agonobody makes you use these features, but when or if you come to writing a library, you may well find them useful.
- uecker 3y agoI switched back to C from C++. The reasons were that C removes a lot of unnecessary complexity which helps concentrating at the problem at hand. It also removes a lot of features that when used incorrectly makes the code much harder to understand. So if one often has to work with code written by unexperienced programmers (as I have to do), I found C++ very problematic. The stronger type checking is largely a myth.
- chlorion 3y agoIt's definitely not a myth. A trivial example is assigning pointers to incompatible types or passing them to incompatible function parameters not being an error. GCC 14 and Clang 16 are only just now making these errors by default. C++ never had this problem. Another example, is having type safe generic functions and classes. Using void* to pass around arbitrary types is something that you don't need to do in C++ because it supports generic programming. In C++ you can for example, pass an array of a specific length to a function, and make it a compile time error to pass an array of incorrect length, using std::array. In C arrays decay to pointers. static_case is also a thing in C++ that allows you to cast between types much more safely. There are so many things that I could probably spend several hours typing them out and I don't think that is really needed. C++ is certainly more type safe than C, whether or not you think the tradeoffs it makes are worth is something to debate for sure, but it gives you tools to write type safe code that simply don't exist in C. https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3...
- uecker 3y agoOk, let's debunk this point for point: - passing incompatible types is a constraint error in C just as in C++. Whether this is a warning or not depends on the compiler and on compiler flags. And as you observed yourself, the defaults are now even the same. - Passing void* around is also generally not necessary in C. - There is no reason to let arrays decay in pointers in C. One can take the address of an array and then get the same type checking. - Whether static_casts really makes much of a difference is debatable. In my C code I avoid casts and the rare exceptions I wrap in type-safe macros. So in summary, I think this just confirms that C++ people think it is safer because they do not know how you would do this in modern C.