Re: C++ more efficient than C?

Discussion in 'C Programming' started by Ian Collins, Apr 6, 2008.

  1. Ian Collins

    Ian Collins Guest

    copx wrote:
    >
    > So C coders who care about efficiency should switch to C++?
    >

    Are you trying to start a flame war?

    In some instances (typically where inlined function templates can
    replace functions with void* parameters) C++ will be faster. Because
    the C++ standard library incorporates the C standard library, C++ code
    should never have to be slower.

    --
    Ian Collins.
     
    Ian Collins, Apr 6, 2008
    #1
    1. Advertising

  2. Ian Collins

    Ian Collins Guest

    copx wrote:
    > "Ian Collins" <> schrieb im Newsbeitrag
    > news:...
    >> copx wrote:
    >>> So C coders who care about efficiency should switch to C++?
    >>>

    >> Are you trying to start a flame war?

    >
    > No, if that were my intention, I would have crossposted this to
    > comp.lang.c++ for maximum effect! ;)
    >

    Ho No! Please don't we've had another Java troll stirring things up
    over there!

    >> In some instances (typically where inlined function templates can
    >> replace functions with void* parameters) C++ will be faster. Because
    >> the C++ standard library incorporates the C standard library, C++ code
    >> should never have to be slower.

    >
    > Of course, but the interesting claim here is that you should NOT use C style
    > code but modern C++ abstractions, because they are not only more readable
    > and expressive, but also more efficient. The second part (they actually
    > being more efficient) was news to me.


    The only place C++ will win the performance race is where the *language*
    offers an advantage, which is why sorting is often cited as an example.
    A lot of C++ code (including libraries) is written either in the C
    subset of C++ or using constructs that can be implemented equally well in C.

    > Well, the inlined function templates superiour to void * functions thing
    > certainly makes sense. Maybe I should finally "move on" after all.
    > However, I compiled both examples with the current version of GCC (on
    > Win32-x86), and there is at least one area where C won: code size. The size
    > difference between the resoluting executables was grotesque: C code => 5KB,
    > C++ code => over 400KB! (both binaries optimized for size and stripped!)
    >

    That'll be all those inlined templates! Seriously, there is nearly
    always a performance/size trade-off. Not always this big though.

    --
    Ian Collins.
     
    Ian Collins, Apr 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maadhuu

    why is double more efficient than float ?

    maadhuu, Sep 14, 2005, in forum: C Programming
    Replies:
    14
    Views:
    850
    Emmanuel Delahaye
    Sep 17, 2005
  2. Replies:
    85
    Views:
    1,496
    James Kanze
    Apr 21, 2008
  3. Re: C++ more efficient than C?

    , Apr 6, 2008, in forum: C Programming
    Replies:
    94
    Views:
    1,986
    James Kanze
    Apr 21, 2008
  4. Steven D'Aprano
    Replies:
    0
    Views:
    146
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    119
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page