3 ms·
Write C code. Compile with C++ compiler. Catch lots of bugs at compile time.
by zabzonk 7y ago
Write C code. Compile with C++ compiler. Catch lots of bugs at compile time.
- xamuel 7y agoOr even better, compile with a C compiler with proper flags set (like -Wall). Catch lots of bugs and also enjoy blazing fast compile time!
- zabzonk 7y agoCompilation speed for C++ is a function of the complexity of the code being compiled (particularly templates), otherwise a C++ compiler will typically compile C code (if it is compilable) at the same speed as a C compiler.
- stevekemp 7y agoYou'll probably find you're missing available warnings unless you add `-Wextra` too.
- dkersten 7y agoYeah use the few features that are beneficial, ignore the rest.
- deleted 7y ago[deleted]
- slacka 7y ago> Write C code. Compile with C++ compiler. What C only compiler were you thinking of? Most of the ones I can think of are toy compilers. If you're making a game, you're going to be using clang/MSVC/gcc. For catching bugs early, at least as important as the compiler are * Enabling additional compiler warnings and -Werror * Checking for memory leaks with valgrind * checking for Undefined Behavior with UBSan * Using mix of static code analysis tools such as Coverity, PVS-Studio, and the Clang Static Analyzer
- ssalazar 7y agoAll of those compiler families have separate C and C++ compilers. They’re saying to use g++ to compile your .c’s instead of gcc.
- slacka 7y agoAssuming OP is correct, I learned something new today. I knew running g++ on .c would produce different results based on differences in the language like sizeof('x') and differences in extern. A quick google didn't turn up any differences between warnings between g++ and gcc. I'll have to look into this.
- gray_-_wolf 7y agoC++ is not a superset of C. There is valid C code not compilable with C++ compiler.
- kccqzy 7y agoThe point is to eschew the use of C features not supported by C++ in order to catch bugs. Just read up on the incompatibilities deliberately introduced by the C++ committee and you'll likely agree that these are good things. Implicit conversions to void*? No thank you. Tentative definitions? I don't need that so give me an error.
- gray_-_wolf 7y agoYeah for example designated initializers. Such a useless feature... /s