4 ms·
Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.
by Kranar 1y ago
Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.
- lionkor 1y agoDo you have a couple of real world examples?
- adastra22 1y agoEmbedded systems, for example.
- teraflop 1y agoI know it used to be, but is it really still common for embedded systems to use weird architectures that G++/Clang don't support?
- adastra22 1y agoUnless it is a popular system or common architecture, yes.
- jenadine 1y agoCould you show me an example of a micro controller still supported today which doesn't have a C++ compiler?
- foldr 1y agoThe 8051. I think C++ compilers technically exist for it, but for most hardware the only practical choice is the Keil C51 compiler, which is C89.
- jjmarr 1y ago> is it common for weird architectures to exist? > yes, unless you're using a common one.
- adastra22 1y agoThat isn’t a contradiction.
- pjmlp 1y agoOnly very weird ones that barely support C like PIC, most ones support at least C++98 or C++11.
- mikepurvis 1y agoAny established C codebase, for example the kernel or Postgres? Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.
- neonz80 1y agoI'm not sure about other compilers, but compiling C code as C++ with MSVC ends up with pretty much the exact same code, instruction by instruction. C++ is a bit more strict though especially with casting, so a lot of code won't compile out of the box.
- vbezhenar 1y agoC++ code compiles to a different function names in object file (name mangling). You probably need to put a lot of ugly `#ifdef __cplusplus extern "C" {` boilerplate in your headers, otherwise C and C++ files will not compile together.
- winocm 1y agoDon't forget the infamous pattern used in some C projects too: struct foo decl = { .member = /* ... */ .next = &(struct nested_pointer) { .nested_member = /* ... */, }, .array = (struct nested_array[]) { [0] = { /* ... */ }, } }; This pattern does not work in C++ as the nested declarations become temporaries.
- charcircuit 1y agoNothing is stopping you from linking C++ code to Postgres.
- cryptonector 1y agoBut if you want to _contribute_ to PostgreSQL, it has to be in C.
- 1y ago
- rectang 1y agoWriting extensions for projects that support C extensions but may not support C++ extensions, e.g. many dynamic languages.
- Snarwin 1y agoYou can still write the extension in C++ and expose an extern "C" interface.
- rectang 1y agoThat's possible, but then the people building your extension need a C++ toolchain. The question was "please provide examples where switching to C++ involves jumping through even more hoops", and in my view requiring downstream to use a C++ environment when they're expecting to use a C environment qualifies.
- uecker 1y agoTrue. For me, C++ itself is the maze of hoops I would rather want to avoid.
- pjmlp 1y agoMost C compilers are C++ toolchain as well, we are no longer in the 1990's. Unless of course the project is using such a old compiler.
- rectang 1y agoProblems in this domain arise more because you’re wandering off the beaten path for configuration and tooling than because the systems lack absolute capabilities. If you don’t want to build your extension the way that the extension framework expects you, all sorts of annoyances show up. Maintaining an cross-platform compatible C extension is hard enough already.
- _proofs 1y agoliterally a good majority of existing embedded software coupled to applications in safety -- devices used by fire safety and first responders.