Thoughts from Greg Comeau on C++, OO, Programming, Learning

(c) © 1990-2013 Comeau Computing. All Rights Reserved.
I have a number of thoughts I will be providing here from time to time. The first set will be about books and learning C++. I hope to have this available by summer 2000. Check back soon for those details and other information.
-- Greg

Here's a first entry (July 23, 1999):
Why do some people say that C is still better than C++?
Can't they see that C++ is a superset of C, and that although C++ has additional features, it does not force you to use them?

Clearly languages can become "religious" for some folks, and so some people are just being biased. However, "pure" C definitely remains in play in areas such as:

  1. Legacy systems
    Some folks still need even K&R C.
  2. The cost of retraining (in C++) is not (yet) practical for some.
    This often ties in with (1), but doesn't have to.
  3. The platform you are on does not have a C++ available.
    This is clearly much less so than previously, but still valid in some cases (though we're always available to port Comeau C++).
  4. Culture/first language/etc.: Some people just love C and/or just don't like C++
IMO, (1) is the only real long term barrier for some projects, though (2) and (3) clearly have economic ties that would be clearly impractical/prohibitive for many companies.

On a strictly technical basis though, I agree with the initial questions. Taking a literal perspective, C++ is not a true super set of C, but from a practical perspective it is. Most ANSI C'd code is also easily C++'d code too. For instance, all the code in K&R's 2nd "ANSI C" edition of The C Programming Language can be (and in fact was) compiled with a C++ compiler.

This then begs these questions/issues which come up often:

  1. Is there any C style which cannot be used in C++?
    I don't know any. Therefore, it is immediately useful.
    And in most cases, w/o a penalty.
  2. Is there not one thing in C++ that looks attractive to the C++ nay sayers?
    I find it hard to believe that anybody would say no.
    Again, this makes it immediately useful.
  3. Don't I have to use the OO parts of C++?
    No, not at all.
  4. If I don't use C++ for OO, then what use is C++, why not just stick with C?
    Let me elaborate on the previous response then. No, you don't have to use the OO parts of C++ at all, though I wouldn't know why you wouldn't if it were appropriate. C++ is often termed an OOL, however, I very much prefer to say that's misguided and instead to say that C++ is a multi-paradigmed language. And oh, BTW, one of those paradigms is OO. This is significant because C++ also supports all the C styles, just data abstraction, plus generic programming, etc. Who are you to say what's best for something without knowing about it?

    Consider a recent discussion I observed. In the discussion, one person said something along the lines of that somebody wouldn't be much of a C++ programmer if they couldn't write straight C code too. This met a response that if somebody used C++ just to write plain old C, then they still were not much of a good C++ programmer! The latter person correctly pointed out that a good C++ programmer wouldn't necessarily program like a good C programmer would.

    Then again, neither person brought forth the issue that we all have different needs to address in our work environment, and therefore we all have our own "programming universe" to understand and maintain. This might indeed see some folks to have no need for say virtual functions. It's not often to find somebody just in need of the C subset parts, but I've known it to be the case many times. This does not mean that those people were doing something wrong. Most had some real constraints to deal with, and so hence made the correct engineering compromises. Considering the programming public at large though, clearly somebody constraining their situation like that, that is, without considering their specific situation and needs of their application, would probably not be making a wise decision.

  5. C++ is slower and bigger that C.
    I've heard this claim for some 14 years now, and I've yet to hear the claimant prove their case with such a blanket statement. Yes, I bet you can find slow and big C++ programs, just like you can find big and slow C programs. Please be aware of (inappropriate) small tests cases, pro for either side, that are used as blanket proofs by some folks. Sly is the person who does not discuss the limitations of their example.
  6. C++ is more complicated. C is a simpler language.
    This is true. However, it does not mean that everything across the whole board is this total monster. Also, intuition is often wrong. For instance, although the C grammar might be simple, things such as C pointers, the preprocessor, routines such as printf/scanf/gets, lack of type checking for functions, etc. are not simple in C. In fact, some are quite hard and obtuse. There is no such thing as a free lunch, and saying that because C is simpler is not illuminating the full situation, or of its impacts. For instance, saying that discards issues of directly modeling concepts in code using features meant for those things. Knock, Knock, get it?
  7. C++ cannot be taught as a first language.
    Well, it has been done so, successfully. Yes, C++ has many gotchas, however, they do not preclude proper education mechanisms and tactics. They also do not preclude the creative and conceptual aspects of learning to program, where the focus of a student should be directed to. Indeed, a course or book teaching syntax features as the primary organization vehicle is misleading and confusing, for any language. This is why suggestions to teach Basic or Pascal first cannot quite hold up, often not even for the short term. They alone are insufficient instructors. People write code, programming languages don't.
Mind you, this may sound like I'm attacking C. No, far from it. I still love C, most especially its subset in C++.

For some addition points, check out the "General C/C++ Issues" link from the Comeau home page which can also be found starting at

- Greg

(c)© 1992-2013 Comeau Computing. All rights reserved.

Comeau Computing
91-34 120th Street
Richmond Hill, NY 11418-3214
/* the end */