Is “C/C++” a thing?

apple and orange in crate

I frequently see people using the term “C/C++” as if it were referring to one language.

Part of the confusion that might lead to writing this, and the confusion that can be generated when reading it, is related to the fact that some compilers actually implement both the C and C++ languages. In these compilers, a developer can switch between languages using a compiler option or by naming their source files with different extensions (e.g., the .C extension or the .CPP extension). Microsoft’s Visual C++ is an example of this type of combined compiler.

Whether or not it’s misleading to use the term “C/C++” really depends on context.

In general, you can’t go wrong by being explicit, treating the two languages as separate entities.

C and C++ are separate and distinct programming languages, and have continued to diverge as they have evolved. Contrary to what you might have heard or read, the C language has never been a proper subset of the C++ language. (Sure, very early C++ compilers generated C source code as their output, but that’s a completely different issue. Someone can write a Fortran compiler that generates C source code as its output, but that doesn’t make the Fortran language a superset of the C language.) Ignoring all the obvious additional keywords and features of C++, there are many other differences between the two languages. To get an idea of some (but not all) of the differences between C and C++, follow this link.

That said, there is definitely a significant overlap between the two languages. C source code that is carefully written to ensure forward compatibility with C++ can be compiled in C++ and generate the same behavior. But doing so requires attention to and avoidance of the subtle and not-so-subtle differences between the two languages. Without following this set of disciplines (which are not enforced by the C compiler), C code won’t necessarily compile under C++, or if it does happen to compile, won’t necessarily behave the exact same way.

If you’re talking about code that has been written to compile under either C or C++ to generate the exact same results, then using the term “C/C++” is okay. Likewise, if you’re talking about a specific language feature (e.g., for loop, if statement, etc.) that is clearly 100% compatible between the two languages, the “C/C++” term is okay. But that’s where the okay-ness of the term “C/C++” ends.

If you’re talking about something that is not well understood as 100% compatible between the two languages, or the use of the term “C/C++” introduces any ambiguity into your question or statement, then it’s best to avoid using the term.

Bottom line: You can’t go wrong by keeping them separate. At the end of the day (and at all other times of the day), C and C++ are two distinct programming languages.

Leave a Reply