Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Mar 2002 16:13:26 +0100 (CET)
From:      Harti Brandt <brandt@fokus.gmd.de>
To:        "Eugene L. Vorokov" <vel@bugz.infotecs.ru>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: C vs C++
Message-ID:  <20020305155850.R83273-100000@beagle.fokus.gmd.de>
In-Reply-To: <200203051407.g25E7Cd67446@bugz.infotecs.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 5 Mar 2002, Eugene L. Vorokov wrote:

ELV>I have a small problem. I work for software development company and
ELV>write daemons and console tools for Unix. My boss wants everything
ELV>to be written in C++, because he thinks C++ is cool. I prefer C
ELV>for such tasks, but I cannot really put good arguments of why and
ELV>where C++ can be worse than C. I know many of you prefer C too.
ELV>Can you please explain some disadvantages of C++ comparing to C ?
ELV>Is it slower, does it produce less effective code, why is it like
ELV>that, etc ... or please direct me to some articles where this can
ELV>be explained.
ELV>
ELV>I apologize for the offtopic whenever it happens, but this issue
ELV>really pisses me off now.

Well there are (at least) two reasons, why I wouldn't use C++ for the
type of program I suppose you are writing:

1. The machine model used by C more or less maps directly into the
   machines used by most computers. By looking at a statement you can
   more or less guess what the compiler will do. In C++ this is not
   the case for (at least) two features: exceptions and virtual methods.
   Both of these features have an overhead, that cannot be estimated in
   advance. You can of course not use these features.

2. C++ turns out to be harder to read except it is extremly good written.
   This stems from several features of the language:

   a) operator overloading. Seeing a '+' doesn't mean that something is
      added. It may even actuall be a subtraction. It may be an
      assignment (a once popular GUI library used '+' to add dialog
      elements to the window on the left side of the '+').

   b) function overloading. In C it is simple to lookup a function when
      you find it called in a program. In C++ you have first to lookup the
      argument types. If these are objects, you have also to find out
      the entire inheritance hierarchy. Then you have a quite complicated
      ruleset to find out, what function is really called.

   c) hidden function calls all over the places. You never know, whether
      a statement does something simple or call a lot of functions.
      'a = b' can invoke dozens of constructors and other functions you
      are not aware of.

Also there were rumours that C++ is less efficient because the resulting
object code tends to consist of many small functions scattered all over
the address space calling each other. This may badly hit cache
performance.

Well, the main problem with this type of question is that the choice of
language depends on the problem you try to solve. For number crunching
Fortran may still be the language of choice, for GUI programming surely it
is C++ (or objc or java, you name it), for inetd it is probably C.

harti
-- 
harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private
              brandt@fokus.fhg.de


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020305155850.R83273-100000>