Wednesday, August 29, 2007

C/C++

Every time you say "C/C++" and lump two very different languages together as one, you're telling the world that you don't know either language. Idiomatic C code is very different from idiomatic C++. Good C++ code has very little that is actually C. Even the problem domains they are used in are different. Usually "C/C++" comes up in Java apologist rants ("Java is unmaintainable you say? Well I spent 10 years chasing memory leaks in "C/C++", it was far worse!") however sometimes you see informed people saying "C/C++". Please, don't.

16 comments:

andyf said...

Umm.. there are many statements that one can make that are true for both C and C++.

Men and women are different.. does that mean that grouping them together by saying "men/women" (or perhaps "people") is not allowed?

Anonymous said...

Men did not evolve from women or vice versa (not wanting to start some kind of religious debate here...!), so that isn't a good analogy.

Saying "C/C++" is more akin to treating apes and humans as the same species.

Anonymous said...

That just isn't analogous. Without wanting to spark some kind of religious debate, men did not evolve from women, or vice versa.

Saying "C/C++" is more akin to treating humans and apes as the same species.

FMota said...

I hadn't thought about this before, but I agree with Slava here.

Andy: there aren't many cases where it makes sense to not lump men and women together. Conversely, there are many cases where it doesn't make sense to lump C and C++ together.

Anonymous said...

For better or worse, C++ is a strict superset of C. (I'm going to gloss such issues as implicit casts from void*.)
So there's a C++ spectrum with 'pure' C89 (no C++ extensions) at one end, and full-on boost/STL code at the other.

Say I decide to take some valid C89 code and wrap it in a C++ namespace. You think that should be called C++, and we should ignore the fact that it's closer in spirit to C? Trying to pretend that there's no connection between C and C++ whatsoever doesn't seem like a particularly useful viewpoint.

I think C/C++ is perfectly valid as a description of the language family, in much the same way as, say Lisp/Scheme.
Or perhaps you'd prefer "the Algol family"? "BCPL derivatives"?

If you're going to get worked up about these kinds of thing, "C+" is a far more egregious term than "C/C++" IMHO.

pabs said...


For better or worse, C++ is a strict superset of C. (I'm going to gloss such issues as implicit casts from void*.)


Really, when did that happen?

pabs@halcyon:~> cat ./ohreally.c
#include <stdio.h>

int main(int argc, char *argv[]) {
int x = 6 //**/ 2 +
-5;
printf("%s: x = %d\n", argv[0], x);
return 0;
}
pabs@halcyon:~> for i in c89 c++; do $i -o ohreally-$i ./ohreally.c; ./ohreally-$i; done
./ohreally-c89: x = -2
./ohreally-c++: x = 1

Also, what does int foo() mean in C? How about C++?

Slava Pestov said...

Wow, it's always the least interesting posts which generate all the discussion.

Anonymous said...

Wow, it's always the least interesting posts which generate all the discussion.

What else do you expect from a bunch of software engineers.

Anonymous said...

Absolutely correct. And the fact that the "C/C++" expression is everywhere makes me a bit uneasy because it indicates that a lot of the information (memes, ideas) you can find on the internet is just a copy-paste from somewhere else. Every thing gets repeated without any thought. The real gems get buried under a ton of nonsense.

Anonymous said...

>That just isn't analogous. Without >wanting to spark some kind of religious >debate, men did not evolve from women, or >vice versa.

>Saying "C/C++" is more akin to treating >humans and apes as the same species."

Not implicitly: consider "humans and apes are both mammals", "humans and apes look alike", or even "similarities found in behaviour of humans and apes".

Anonymous said...

Bad claim because although C++ is more complex and has more to offer, backwards compatibility always ensured.

One reason why D was created, man.

Anonymous said...

D was created to break from C++ compatibility to C.

Saying C++ is no C isnt a big truth there, or? ;)

Anonymous said...

pabs@halcyon:~> for i in c89 c++ c99; do $i -o ohreally-$i ./ohreally.c; ./ohreally-$i; done
./ohreally-c89: x = -2
./ohreally-c++: x = 1
./ohreally-c99: x = 1

Anonymous said...

pabs@halcyon:~> for i in c89 c++ c99; do $i -o ohreally-$i ./ohreally.c; ./ohreally-$i; done
./ohreally-c89: x = -2
./ohreally-c++: x = 1
./ohreally-c99: x = 1

Anonymous said...

Dude, humans are apes.

Anonymous said...

int x = 6 //**/ 2 +
-5;


Do you not get what superset means? //-style comments are an addition to C++ which is what causes the above code to produce different results. That's because C++ is a superset of C.