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:

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

    ReplyDelete
  2. Anonymous5:53 PM

    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.

    ReplyDelete
  3. Anonymous5:55 PM

    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.

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

    ReplyDelete
  5. Anonymous8:26 PM

    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.

    ReplyDelete

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

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

    ReplyDelete
  8. Anonymous4:21 AM

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

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

    ReplyDelete
  9. Anonymous5:06 AM

    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.

    ReplyDelete
  10. Anonymous5:26 AM

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

    ReplyDelete
  11. Anonymous7:06 AM

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

    One reason why D was created, man.

    ReplyDelete
  12. Anonymous7:07 AM

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

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

    ReplyDelete
  13. Anonymous2:00 PM

    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

    ReplyDelete
  14. Anonymous2:01 PM

    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

    ReplyDelete
  15. Anonymous5:28 PM

    Dude, humans are apes.

    ReplyDelete
  16. Anonymous7:38 AM

    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.

    ReplyDelete