Why We Use C Than C++...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sonugeetha@gmail.com

    Why We Use C Than C++...

    Hi, Please help me in this regard...
    All the kernel level programs are written in C... (i.e: Open Source
    LINUX)... Why are they not using C++... I personally feel that C++ is
    more easy to code than C... When i searched in our encyclopedia (i.e
    Google), i came up with several answers, telling "C is much faster than
    C++ and most kernal prgms uses only C" ... But why is it so...? Why
    they use C for these OS based programs.. Please Help me with detailed
    explanation...

    Cheers,
    Balaji Jayaraman...

  • EventHelix.com

    #2
    Re: Why We Use C Than C++...

    In a well developed C++ program, there isn't much difference between C
    and C++ performance.

    The following articles describe a mapping from C++ to C code.




    The biggest performance hit in C++ comes from the implicit passing of
    the "this" pointer in every
    function. However, C++ more than makes up for this by better locality
    of reference. This translates
    to improved cache performance.

    --
    EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
    System Design with Sequence Diagrams in PDF and Word EMF

    Comment

    • Richard Heathfield

      #3
      Re: Why We Use C Than C++...

      sonugeetha@gmai l.com said:
      [color=blue]
      > Hi, Please help me in this regard...
      > All the kernel level programs are written in C... (i.e: Open Source
      > LINUX)... Why are they not using C++... I personally feel that C++ is
      > more easy to code than C... When i searched in our encyclopedia (i.e
      > Google), i came up with several answers, telling "C is much faster than
      > C++ and most kernal prgms uses only C" ... But why is it so...? Why
      > they use C for these OS based programs.. Please Help me with detailed
      > explanation...[/color]

      Partly because C is faster (in places). Partly because it's simpler, so it's
      easier to get right. But mostly, I think, because C came first. When the
      kernel was first being written, C had already firmed up, whilst C++ was
      still in a state of considerable flux. And, once it's /written/ in C, if a
      reasonable job was made (which certainly seems to be the case), why on
      earth would anyone bother to rewrite it?

      --
      Richard Heathfield
      "Usenet is a strange place" - dmr 29/7/1999

      email: rjh at above domain (but drop the www, obviously)

      Comment

      • Dag-Erling Smørgrav

        #4
        Re: Why We Use C Than C++...

        Richard Heathfield <invalid@invali d.invalid> writes:[color=blue]
        > Partly because C is faster (in places). Partly because it's simpler,
        > so it's easier to get right. But mostly, I think, because C came
        > first.[/color]

        Another important factor is that C++ requires more run-time support
        code to work properly.

        DES
        --
        Dag-Erling Smørgrav - des@des.no

        Comment

        • Walter Roberson

          #5
          Re: Why We Use C Than C++...

          In article <1137065013.641 067.148570@f14g 2000cwb.googleg roups.com>,
          EventHelix.com <eventhelix@gma il.com> wrote:[color=blue]
          >In a well developed C++ program, there isn't much difference between C
          >and C++ performance.[/color]
          [color=blue]
          >The following articles describe a mapping from C++ to C code.[/color]
          [color=blue]
          >http://www.eventhelix.com/RealtimeMa...erformance.htm
          >http://www.eventhelix.com/RealtimeMa...rformance2.htm[/color]

          I just read through those two articles. They are short on details,
          make a lot of assumptions about -how- one programs in C; and the
          conclusions are a bit of hand-waving not justified by the work that
          has gone before.

          In particular, I would say that the "Locality of Reference" conclusion
          is based upon implementation factors rather than on language design,
          and that the reasoning of that section appears faulty to me.
          --
          "It is important to remember that when it comes to law, computers
          never make copies, only human beings make copies. Computers are given
          commands, not permission. Only people can be given permission."
          -- Brad Templeton

          Comment

          • Walter Roberson

            #6
            Re: Why We Use C Than C++...

            In article <86ace1sayk.fsf @xps.des.no>,
            =?iso-8859-1?q?Dag-Erling_Sm=F8rgr av?= <des@des.no> wrote:[color=blue]
            >Richard Heathfield <invalid@invali d.invalid> writes:[color=green]
            >> Partly because C is faster (in places). Partly because it's simpler,
            >> so it's easier to get right. But mostly, I think, because C came
            >> first.[/color][/color]
            [color=blue]
            >Another important factor is that C++ requires more run-time support
            >code to work properly.[/color]

            The C++ Standard Library is many times as big as the C Standard Library,
            And if one is reading through the C++ standard, it can be quite
            difficult to figure out what the tradeoffs are between using the
            several different approaches to any one task that are offered by
            the C++ Standard Library.
            --
            Is there any thing whereof it may be said, See, this is new? It hath
            been already of old time, which was before us. -- Ecclesiastes

            Comment

            • Walter Roberson

              #7
              Re: Why We Use C Than C++...

              In article <1137064443.960 141.168050@g49g 2000cwa.googleg roups.com>,
              sonugeetha@gmai l.com <sonugeetha@gma il.com> wrote:[color=blue]
              >All the kernel level programs are written in C... (i.e: Open Source
              >LINUX)... Why are they not using C++...[/color]

              If I understand correctly, there has been work on C++ for the Linux kernel.
              For example,



              According to the Linux FAQ, C++ is not generally well received for
              the kernel, for a variety of reasons. The FAQ includes a quotation from
              Linus from 2004:

              In fact, in Linux we did try C++ once already, back in 1992.

              It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.

              The fact is, C++ compilers are not trustworthy. They were even worse
              in 1992, but some fundamental facts haven't changed:
              o the whole C++ exception handling thing is fundamentally broken.
              It's _especially_ broken for kernels.
              o any compiler or language that likes to hide things like memory
              allocations behind your back just isn't a good choice for a kernel.
              o you can write object-oriented code (useful for filesystems etc) in C,
              _without_ the crap that is C++.

              In general, I'd say that anybody who designs his kernel modules for C++
              is either
              o (a) looking for problems
              o (b) a C++ bigot that can't see what he is writing is really just C
              anyway
              o (c) was given an assignment in CS class to do so.
              Feel free to make up (d).
              --
              Programming is what happens while you're busy making other plans.

              Comment

              • henryk.mueller@gmx.de

                #8
                Re: Why We Use C Than C++...

                > Another important factor is that C++ requires more run-time support[color=blue]
                > code to work properly.[/color]

                Nope.

                The objective of C++ is that you do not pay for features you do not
                use.

                C++ is not faster or slower than C if you DO the same.

                For example: C functions have no parameter "this". But static C++
                function do not have a "this" parameter either.

                So, compare only apples with apples....

                I use C++ in an embedded environment. Mostly because of it's better
                code encapsulation. You can write small and lean wrappers for
                interfaces that actually contain mostly inline functions. So you have
                no overhead but you can protect the user of your class from using it in
                an unwanted way much better than in C, i.e. forget to call init in C
                vs. do the init within the constructor.

                There are a lot examples of C++ features that are done at compile time
                and have no effect at runtime. They all help you to write more robust
                code. Reference objects vs. pointers, const methods, const return
                values and all this stuff...

                The are only 3 reasons to use C over C++:
                - you have no decent C++ compiler for your platform
                - you have to continue a C project
                - you are not allowed to use C++ because your boss still believes that
                C++ is SLOW

                Greets

                Henryk

                Comment

                • Andrew Poelstra

                  #9
                  Re: Why We Use C Than C++...


                  sonugeetha@gmai l.com wrote:[color=blue]
                  > Hi, Please help me in this regard...
                  > All the kernel level programs are written in C... (i.e: Open Source
                  > LINUX)... Why are they not using C++... I personally feel that C++ is
                  > more easy to code than C... When i searched in our encyclopedia (i.e
                  > Google), i came up with several answers, telling "C is much faster than
                  > C++ and most kernal prgms uses only C" ... But why is it so...? Why
                  > they use C for these OS based programs.. Please Help me with detailed
                  > explanation...
                  >
                  > Cheers,
                  > Balaji Jayaraman...[/color]

                  As has been mentioned, C hides a lot of memory allocations and stuff
                  from the user-programmer; obviously, you don't want that happening in a
                  kernel.

                  What I think is a far more annoying problem is the fact that
                  interfacing C++ is Assembler is hard, because C++ mangles the funtion
                  names to handle overriding properly. There are more details in 'PC
                  Assembly Language' by Dr. Paul Carter.

                  When doing kernels, you'll likely be interfacing with lots of low-level
                  ASM functions to handle hardware interrupts and what not; C is the most
                  portable language (across different compilers) for doing this.

                  Comment

                  • Flash Gordon

                    #10
                    Re: Why We Use C Than C++...

                    Walter Roberson wrote:[color=blue]
                    > In article <1137065013.641 067.148570@f14g 2000cwb.googleg roups.com>,
                    > EventHelix.com <eventhelix@gma il.com> wrote:[color=green]
                    >> In a well developed C++ program, there isn't much difference between C
                    >> and C++ performance.[/color]
                    >[color=green]
                    >> The following articles describe a mapping from C++ to C code.[/color]
                    >[color=green]
                    >> http://www.eventhelix.com/RealtimeMa...erformance.htm
                    >> http://www.eventhelix.com/RealtimeMa...rformance2.htm[/color]
                    >
                    > I just read through those two articles. They are short on details,
                    > make a lot of assumptions about -how- one programs in C; and the
                    > conclusions are a bit of hand-waving not justified by the work that
                    > has gone before.
                    >
                    > In particular, I would say that the "Locality of Reference" conclusion
                    > is based upon implementation factors rather than on language design,
                    > and that the reasoning of that section appears faulty to me.[/color]

                    In addition, the articles are either a long way out of data (over 15
                    years) or the author does not really know C as it has been since it was
                    standardised. I say this because it is including malloc.h instead of the
                    standard header stdlib.h. Whichever is the case, it casts even further
                    doubt on whether the author is qualified to compare the languages.
                    --
                    Flash Gordon
                    Living in interesting times.
                    Although my email address says spam, it is real and I read it.

                    Comment

                    • James S. Singleton

                      #11
                      Re: Why We Use C Than C++...

                      On Thu, 12 Jan 2006 03:14:04 -0800, sonugeetha@gmai l.com wrote:
                      [color=blue]
                      > Hi, Please help me in this regard...
                      > All the kernel level programs are written in C... (i.e: Open Source
                      > LINUX)... Why are they not using C++... I personally feel that C++ is more
                      > easy to code than C... When i searched in our encyclopedia (i.e Google), i
                      > came up with several answers, telling "C is much faster than C++ and most
                      > kernal prgms uses only C" ... But why is it so...? Why they use C for
                      > these OS based programs.. Please Help me with detailed explanation...[/color]

                      Another reason that no one has pointed out yet: Because object orient
                      design is not the silver bullet that many want to believe, and because
                      object orient design is something that comes naturally to many programmers
                      (good and bad) but doesn't to just as many (also good and bad).


                      Comment

                      • jacob navia

                        #12
                        Re: Why We Use C Than C++...

                        James S. Singleton a écrit :[color=blue]
                        >
                        > Another reason that no one has pointed out yet: Because object orient
                        > design is not the silver bullet that many want to believe, and because
                        > object orient design is something that comes naturally to many programmers
                        > (good and bad) but doesn't to just as many (also good and bad).
                        >[/color]

                        YES!

                        And I would add another one:

                        Complexity with more complexity until no one on earth,
                        (besides Bjarne maybe) is able to understand the whole
                        language.

                        Man years of toiling to build incredible fragile compilers
                        that are incompatible with each other because not one of
                        them shares the same bug set. Obviously.

                        I have watched Bjarne and his followers start with the idea of a
                        "better C" and get swallowed alive by the dragons of complexity.

                        Automatic destructors can be replaced easily with a
                        garbage collector, what simplifies the whole thing
                        quite a bit without adding more complexity and new
                        features to the language itself.

                        Templates are one approach to genericity but that can be
                        better handled with metaprogramming , i.e. compile
                        time functions.

                        jacob




                        Comment

                        • Keith Thompson

                          #13
                          Re: Why We Use C Than C++...

                          henryk.mueller@ gmx.de writes:
                          [...][color=blue]
                          > The are only 3 reasons to use C over C++:
                          > - you have no decent C++ compiler for your platform
                          > - you have to continue a C project
                          > - you are not allowed to use C++ because your boss still believes that
                          > C++ is SLOW[/color]

                          - you happen to know C better than C++;
                          - you happen to *like* C better than C++;
                          ....

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Keith Thompson

                            #14
                            Re: Why We Use C Than C++...

                            jacob navia <jacob@jacob.re mcomp.fr> writes:
                            [...][color=blue]
                            > Automatic destructors can be replaced easily with a
                            > garbage collector, what simplifies the whole thing
                            > quite a bit without adding more complexity and new
                            > features to the language itself.[/color]

                            As I understand it, garbage collection only reclaims allocated memory;
                            destructors can perform any arbitrary cleanup actions (closing files,
                            for example).

                            --
                            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                            We must do something. This is something. Therefore, we must do this.

                            Comment

                            • jacob navia

                              #15
                              Re: Why We Use C Than C++...

                              Keith Thompson a écrit :[color=blue]
                              > jacob navia <jacob@jacob.re mcomp.fr> writes:
                              > [...]
                              >[color=green]
                              >>Automatic destructors can be replaced easily with a
                              >>garbage collector, what simplifies the whole thing
                              >>quite a bit without adding more complexity and new
                              >>features to the language itself.[/color]
                              >
                              >
                              > As I understand it, garbage collection only reclaims allocated memory;
                              > destructors can perform any arbitrary cleanup actions (closing files,
                              > for example).
                              >[/color]

                              True, you have to invoke the cleanup yourself.
                              This may be a lot of work, or not relevant, depending on your
                              application.

                              Using exception handling, it is easy to do automatic cleanups
                              using the __finally clause. The exception handling provided by
                              lcc-win32 is just the compiler side of the native one
                              provided by the Win32 system.

                              jacob-

                              Comment

                              Working...