I've seen a lot of questions around that use improperly the expression "C/C++". The reasons in my opinion are:
- Newbie C and C++ programmers probably don't understand the difference between the two languages.
- People don't really care about it since they want a generic, quick and "dirty" answer
While C/C++ could sometimes be interpreted as "either C or C++", I think it's a big error. C and C++ offer different approaches to programming, and even if C code can be easily implemented into C++ programs I think that referring to two separate languages with that single expression ( C/C++ ) is wrong.
It's true that some questions can be considered either as C or C++ ones, anyway. What do you think about it?
How do I find the file handles that my process has opened in Linux?
MySQL C API using results
How to build sliding block puzzle software for mobiles
It's something that wasn't really wrong at first, but is getting more-so all the time..
EINTR error for semop call
The basic structure is similar enough that most simple questions do still work between the two, though.
Is it feasible to make iPhone apps using just OpenGL and not Cocoa Touch?
There is an entire Wikipedia article on this topic: http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B.
Are memory leaks ever ok?
The biggest fallacy that comes from this is that because someone is well-versed in C, they will be equally good at C++..
Intercepting traffic to memcached for statistics/analysis
Timer function to provide time in nano seconds using C++
All C++ concepts can be manually coded (but not compiler-enforced) in plain C.. "C/C++" is also valid when referring to compilers and other language/programming tools.
Virtually every C++ compiler available will compile either - and are thus referred to as "C/C++" compilers.
Most have options on whether to treat .C and .CPP files based on the extension, or compile all of them as C or all of them as C++.. Also note that mixing C and C++ source in a single compiler project was possible from the very first C/C++ compiler.
This is probably the key factor in blurring the line between the languages.. Many language/programming tools that are created for C++ also work on C because the language syntax is virtually identical.
Many language tools have separate Java, C#, Python versions - but they have a single "C/C++" version that works for C and C++ due to the strong similarities..
A lot of C code would compile just fine on a C++ compiler.
At the early-student level, a lot of C++ code would still work on a C compiler.. Note that in some circumstances the meaning of the code may differ in very subtle ways between the two compilers, but I suppose that's true in some circumstances even between different brands of C++ compiler if you're foolish enough to rely on undefined or contested/non-conformant behavior..
A C developer would find it difficult to "parse/understand" a C++ source, whereas a C++ developer would not easily recognize the patterns used in a C source.. Thus, if you want to see how far the C is from the C++ in the "C/C++" expression, a good comparison would be the GTK+ C tutorials, and the same in C++ (GTKmm):. C : GTK+ Hello World: http://library.gnome.org/devel/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD. C++ : GTKmm Hello World: http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-helloworld.html. Reading those sources is quite enlightening, as they are, as far as I parsed them, producing exactly the same thing, the "same" way (as far as the languages are concerned).. Thus, I guess the C/C++ "expression" can quite be expressed by the comparison of those sources.. :-). The conclusion of all this is that it is Ok if used on the following contexts:.
- describing the intersection of C and C++
- describing familiarity with C programing as well as C++ programing
- describing compatible code
- justifying keeping to code in a subset of C++ (or C) for candy compatibility with C (or C++) when compatibility is not desired (and in most C++ project, it is not desired because quite limitating).
- asserting that C and C++ can/should be coded the same way (as NOT shown by the GTK+/GTKmm example above)
. While a C answer may not be idiomatic C++ (and vice versa), I think that's one of C++'s big selling points - you can basically embed C into it.
If an idiomatic answer is important, they can always specify C/C++/C++ with STL/C++ with boost/etc.. An answer in lisp is going to be pretty unusable.
But an answer in either C or C++ will be directly usable..
It seems to be a term mostly used by C++ newbies.
We C-only curmudgeons just say "C" and the experienced C++ folks know how much it has diverged from C and so they properly say "C++".. Even if C is (nearly) a subset of C++, this doesn't really have any bearing on their actual usage.
Practically every interesting C feature is frowned upon in modern C++ code: C pointers (use iterators/smart pointers/references instead), macros (use templates and inline functions instead), stdio (use iostreams instead), etc.
etc.. So, as Alex Jenter put it, it's unlikely that anyone who knows either language well would say C/C++.
Saying that you know how to program in "C/C++" is like saying you know how to program in "Perl/PHP"...
sure they've got some significant similarities, but the differences in how they are actually used are vast..
I read the C tag RSS feed, and I see tons of C++ questions come through that really don't have anything to do with C.. I also see this exchange a lot:
Asker: How do you do this in C?
Answer: Use the X library for C++.
Asker: OK, how about someone actually answer my question in C?.
(and I am still improving!).
Isn’t saying “C/C++” wrong?.No, it isn't.
Watcom International Corporation for example, founded more than 25 years ago, called their set of C and C++ compilers and tools "Watcom C/C++", and this product is still developed and available in the open-source form as OpenWatcom C/C++.
sprintfor bit manipulation, I think it can be legitimate (the latter can even be tagged C/C++/Java/C#, I suppose...)..
. From what I've seen, you can write C++ code the C way or the C++ way.
Both work, but C++ code that is not written C style is usually easier to maintain in the long run.. In the end, it all depends on the particular question.
If someone is asking how to concatenate strings, than it is very important whether he wants C or C++ solution.
Or, another example, if someone is asking for a qsort algorithm.
To support different types, you might want to use macros with C and templates with C++, etc..
Please remember that the original implementations of C++ were simply as a pre-compiler that output C code for the 'real' compiler..I have a friend (who writes C++ compilers -- yes, plural), who would take offense to your first sentence.
A compiler whose object code is C source code is every bit as much a compiler as any other.
The essence of a compiler is that it understands that syntax of the language, and generates new code based on that.
A pre-processor has no knowledge of the language and merely reformats its input.. Remember that the C Compilers which would compile the output of those C++ compilers, would themselves output ASM code would would then be run through an assembler..
C++ is an OO language, while C is procedural language.. Do I have to mention templates?. Also, there are differences in C and C++ standards.
If something is good in C, doesn't have to compile in C++.