Isn't saying “C/C++” wrong?


Isn't saying “C/C++” wrong?



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?

1:



MySQL C API using results
C/C++ is a holdout from the early days of C++, where they were much more similar than they were today.


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++

2:


Please remember that the original implementations of C++ were simply as a pre-compiler that output C code for the 'real' compiler.

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..


3:


We in our company have noticed the following curious fact: if a job applicant writes in his CV about "advanced C/C++ knowledge", there is usually a good chance that he really knows neither ;).


4:


The two languages are distinct, but they have a lot in common.

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..


5:


Yes and no.. C and C++ share a lot in common (in fact, the majority of C is a subset of C++).. But C is more oriented "imperating programming", whereas C++, in addition to C paradigm, has more paradigms easily accessible, like functional programing, generic programing, object oriented programing, metaprograming.. So I see the "C/C++" item saying either as "the intersection of C and C++" or "familiarity with C programing as well as C++ programing", depending on the context.. Now, the two languages are really different, and have different solutions to similar problems.

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
But it would not be for:.
  • 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)


6:


I think it's more of the second answer - they want something that's easily integrated into their project.

. 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..


7:


Yeah, C/C++ is pretty useless.

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..


8:


C/C++ often means a programiing style, which is like C and classes, or C and STL :-) Technicaly it is C++, but minimum of its advantages are used..


9:


I agree.

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?.


10:


I use that term myself, and it is because it is my style, I don't use boost, stl or some other things, not even standard C++ libs, like "cout" and "cin", I program C but using classes, templates and other (non-library) features to my advantage.. I can say that I am not a master of C, neither a master of C++, but I am really good at that particular style that I use since 10 years ago.

(and I am still improving!).


11:


I was under the impression that all c code is valid c++ code..


12:


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++.


13:


If it is a complex question needing to write more than one function, yes, it can be wrong.. If it is just to ask a detail about sprintf or bit manipulation, I think it can be legitimate (the latter can even be tagged C/C++/Java/C#, I suppose...)..


14:


Whoever is asking the question should write C, C++ or C/C++ depending on the question.

. 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..


15:


This was too long for a comment, so I had to make it an answer, but it's in response to Jeff B's answer..
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..


16:


I tend to put C / C++ in my questions.. Typically I am looking for something that I can use in my c++ application.. If the code is in C or in C++ then I can use it, so I would rather not just limit the possible answers to one or the other..


17:


Not only these two languages are different, but also the approaches are different.

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++.



70 out of 100 based on 40 user ratings 190 reviews