Comment by pjmlp

17 hours ago

Specially relevant to all those folks that insist on "Coding C with a C++ compiler", instead of safer language constructs, and standard library alternatives provided by C++ during the last decades.

Funny because for a long time the Microsoft MSVC team explicitly recommended compiling C code with a C++ compiler because they couldn't be arsed to update their C frontend for over two decades (which thankfully has changed now) ;)

https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...

  • That thing always baffled me, this huge company building a professional IDE couldn't figure out how to ship updates to the C compiler.

    > it is hard to say no to you, and I’m sorry to say it. But we have to choose a focus, and our focus is to implement (the standard) and innovate (with extensions like everyone but which we also contribute for potential standardization) in C++.

    I mean, yeah if it came from a two member team at a startup, sure focus on C++, understandably. But Microsoft, what happened to "Developers! Developers! Developers!"?

    • It's not baffling, it's remarkably consistent. They implemented Java as J++ and made their version incompatible in various ways with the standard so it was harder to port your code away from J++ (and later J#). They implemented things in the CSS spec almost exactly opposite the specification to lock people into IE (the dominant browser, if you have to make your site work with 2+ incompatible systems which will you focus on?). Not supporting C effectively with their tools pushed developers towards their C++ implementation, creating more lock-in opportunities.

    • It was on purpose, Microsoft was done with C, the official message was to move on to C++.

      The change of heart was the new management, and the whole Microsoft <3 FOSS.

      6 replies →

    • Funnily enough, the intellisense parser does support C syntax because it's using a commercial frontend by edison under the hood. MSVC's frontend doesn't.

  • Yeah, 12 years ago, when governments couldn't care less about nation state cyberattacks, and Microsoft was yet to be called by the Congress to testify on their failures.

Perfectly valid to do if you need to interface with a large C code base and you just want to do some simple OO here and there. Especially if you cannot have runtime exceptions and the like.

This is how I managed to sneak C++ into an embedded C codebase. We even created some templates for data structures that supported static allocation at compile time.

  • What would be an example of "simple OO here and there" that cannot be done cleanly in plain C?

    • Templating on pixel classes so that a blitter builds all supported pixel paths separately and inlines them.

      Yes you can do it less cleanly with macros or inline functions. But you can't do it performantly with struct and function pointers.

    • You can do anything in C that you want to. Of course one can make v-tables and all of that, and even do inheritance.

      But having the "class" keyword is nice. Having built in support for member functions is nice.

      Sometimes a person just wants the simplicity of C++ 2003.

      (In reality I was working on a project where our compiler only supported C++ 2003 and we had a UI library written in C++ 2003 and honestly pure C UI libraries kind of suck compared to just sprinkling in a bit of C++ sugar.)

      2 replies →

  • Yeah, but one should provide C++ type safe abstractions on top.

    Just like one doesn't use Typescript to keep writing plain old JavaScript, then why bother.

I mean as long as your goal is specifically to do that I think it's fine. Using a C++ compiler to compile a C program isn't that rare.