Why C?

This is a discussion on Why C? within the C Programming forums, part of the General Programming Boards category; At my school, the first two semesters of programming instruction are in C. Thereafter, the emphasis seems to shift to ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    595

    Why C?

    At my school, the first two semesters of programming instruction are in C. Thereafter, the emphasis seems to shift to C++ (and some Java). This approach seems to work well; what we learned of C serves as excellent preparation for learning C++. In fact, until yesterday I was under the impression that C++ is precisely a superset of C, and that anything written in C would be compatible with a C++ compiler. In fact, it seemed that C was basically a set of "training wheels" to ease us gently into C++.

    I was surprised to find out, through Mr.C's thread about C99, the David Tribble link that Salem posted there, and other material that I found through google, that the recent evolution of C is making it less compatible with C++.

    And so, I'm wondering why -- what purposes are served by introducing changes in C that are incompatible with C++ (or, why it was not considered appropriate to make the same changes to the C++ standard)?

    Also, since this makes it apparent that there must be categories of users or categories of applications which are providing the impetus for this divergence, I'm wondering who and/or what they are? Who uses C specifically (as opposed to using a subset of C++), and why?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Since C is about 15 years older than C++, this was hardly ever true. C was not invented to make C++ easy to learn, or be "C++ lite".
    That's not what I meant. I'm aware of the history of these languages. In fact, I still refer to Kernighan & Ritchie's book from time to time. But we were given the impression that essentially everything new (in this "family") was being written in C++, and that C programs were for the most part leftovers that were written before C++. Or, in other words, the main reason given for learning C was to be able to maintain old C programs if called upon to do so.

    If you don't know either, and you want to learn an OO programming language, skipping C is probably a good idea.
    Nah. I want to learn them all.


    Anyway..., I'd like to try to get this back to my main question, which is...

    Which types of users and which types of applications (other than those that are just "holdovers" from pre-C++ days) have been using C and not C++, and why?


    (And, secondarily, are there reasons for them to explicitly use a C compiler rather than using a C++ compiler but employing only the procedural elements of C++ and ignoring the OO aspects).

    By the way, I don't mean any of my remarks as a "putdown" directed at C; I'm just trying to understand what it's particular strengths are.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    Obviously, the core difference is that C is procedural, and C++ is OO - so not only, as Salem says, do they require different 'mind-sets', but they are better suited for different purposes. If you accept that they come from the same ancestor, but are totally different programming languages, then you might aswell be asking why have Java and C++, why not just C++?

    Why not just have one Super++ language which does everything brilliantly?

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    19
    Why not just have one Super++ language which does everything brilliantly?
    Either K or R said something like:
    "
    It's actually easier to program in a language that doesn't have every feature"

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Obviously, the core difference is that C is procedural, and C++ is OO
    Not so obvious, and not very convincing.

    You can write entirely procedure-based programs in C++. In fact, except for the (relatively) few things that changed in the 1999 standard revision, just about anything that can be done in C can be done in C++, using the same code.

    As for requiring different mind-sets, that's a characteristic of the programming process, not necessarily of the language. I can put on my "OO" hat and use C++ to write an object-oriented program, or I can put on my "PP" hat and use C++ to write an exclusively procedural program, or I can forget about the hats and write a program that is a combination of both philosophies.

    So, while Salem is of course right that C was not written to be "C++ lite", doesn't the fact that C++ has grown to be so much more versatile, while retaining essentially all of the capabilities it inherited from C, relegate C to a de-facto status of "C++ lite" anyway?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Which types of users and which types of applications (other than those that are just "holdovers" from pre-C++ days) have been using C and not C++, and why?
    In many embedded systems (especially the 8-bitters), C is an easy choice because there is no C++ compiler available for the target processor.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    4
    With all the extra features of C++, doesnt it mean it will come with lots of extra baggage making programs larger and slower?

  8. #8
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    According to my limited knowledge of the topic your question adresses, there is no real difference between c and c++ on your program's size and speed. The amount of overhead used by each language would only be determined by the language's individual header files, and which ones you include in your program. And since all the functions in the header files would be fully optimised, it would most likely be much slower trying to emulate C++ in C.

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Thank you Dave_Sinkula for the best answer. Really, so far I think yours is the only valid reason anyone has yet given for choosing C over C++.


    Anybody have any others?

  10. #10
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    Originally posted by R.Stiltskin
    Thank you Dave_Sinkula for the best answer. Really, so far I think yours is the only valid reason anyone has yet given for choosing C over C++.


    Anybody have any others?
    They were all valid, you just didn't accept them as valid. C is procedural in the idea that what you see is what you get. However, C++, when using OOP, has additional operations that you don't see; Class's for example, a constructor and destructor are called. And yes, one very large reason for choosing C over C++ is when working with electronics. Also, in many circumstances, OOP is not always considered ... how should I put this... the best practice?
    Last edited by Xei; 06-08-2003 at 03:39 PM.
    "What are you after - the vague post of the week award?" - Salem
    IPv6 Ready.
    Travel the world, meet interesting people...kill them.
    Trying to fix or change something, only guaruntees and perpetuates its existence.
    I don't know about angels, but it is fear that gives men wings.
    The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.

    E-Mail Xei

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    C is procedural in the idea that what you see is what you get.
    This is nothing but buzzwords.

    ===================================

    ...C++, when using OOP, has additional operations that you don't see; Class's for example, a constructor and destructor are called.
    Yes, and when not using OOP, a constructor and destructor are not called. So???
    In fact, when not using OOP you can write essentially the same procedural program in C++ as you can in C -- almost EXACTLY the same, it seems. And, if you can't, I wish someone would give a reason why not. I would really like to know, and I'm sure a lot of other people would too.
    People keep reusing the same vague argument -- that some programs call for a procedural rather than an object-oriented approach -- as a reason for using C and not C++. This is not a valid argument, because the same procedural program can be written just as well and just as easily, in C++.
    So far, only Dave_Sinkula has come up with an instance in which there is a compelling reason to use C and not C++.

    ====================================

    And yes, one very large reason for choosing C over C++ is when working with electronics.
    OK, maybe you have something here. But what is the reason?. What is the advantage of C when working with electronics. Specifically, what can you do in C that you can't do in C++, or, what can you do better in C than in C++, and why?

  12. #12
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I don't mean to fuel any C vs C++ battle, but this is something I found interesting:
    Object Oriented Programming in C
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  13. #13
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    This is nothing but buzzwords.
    What I mean is that in C there are not really additional operations in the background. If you add 5 to X, then it would be:

    add eax, 5

    for example, unlike VB and its never-ending background operations because of things like SafeArrays(which are structures in C/C++), etc.

    OK, maybe you have something here. But what is the reason?. What is the advantage of C when working with electronics.
    Read what Dave_Sinkula originally stated. Also, in regards to Electronics, OOP is rarely ever used. For example: If you happen to find a Microprocessor that has a compiler that supports OOP and it is no longer produced, so you are forced to find a new Microprocessor, however, this new Micro Processor does not accept OOP and now you have to make unnecessary major changes to the entire system which could end up costing the company, and your job.
    "What are you after - the vague post of the week award?" - Salem
    IPv6 Ready.
    Travel the world, meet interesting people...kill them.
    Trying to fix or change something, only guaruntees and perpetuates its existence.
    I don't know about angels, but it is fear that gives men wings.
    The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.

    E-Mail Xei

  14. #14
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    > You can write entirely procedure-based programs in C++.

    And you can implement object oriented designs in C. It does take a bit more work and is probably not the most efficient way, but it possible. C++ does have language elements to support the object oriented way of programming. In my opinion, when implementing a design, one should choose the language which fits the system requirements and has the elements to express the designer's ideas in the best way. So for object oriented designs, one should choose for a langauge which supports the object oriented way of programming.

    There's a book of Axel Schreiner called "Object oriented programming in ANSI C", if I remember well.

    > In many embedded systems (especially the 8-bitters), C is an easy choice because there
    > is no C++ compiler available for the target processor.

    Also C++ has elements which make programs in this language larger and slower than programs written in C. There is a subset of C++ defined, called Embedded C++, which has only those elements which keep C++ programs small and don't cause overhead.

    Maybe it is also because embedded systems engineers used to think in terms of "what should the system do" instead of "which objects are interacting". They also programmed in assembly, today still assembly is used a lot, and C is closer to assembly than C++.

    C++ is these days used a lot in large systems than C, because it supports object orientation in a better way. And object orientation is these days the most used way of thinking of people designing systems. Better reusable code, better maintainable code and that kind of things are the goals designers try to reach for in their designs. Object orientation seems to be the solution to reach this goals and therefore developers choose a language which has the tools to support implementing such object oriented designs. So they will choose C++ instead of C.

    Off topic: Java is also an object oriented language and used a lot. But in the embedded world, Java is used mainly for applications and user interface software, C/C++ are used for the lower layers of software.

  15. #15
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >There's a book of Axel Schreiner called "Object oriented programming in ANSI C", if I remember well.

    Near the bottom of the page on the link I posted, this was listed in the references (among others). It is available there as a PDF.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21