Re: Why We Use C Than C++...
- From: Ulrich Eckhardt <doomster@xxxxxxxx>
- Date: Wed, 18 Jan 2006 20:04:22 +0100
sonugeetha@xxxxxxxxx wrote:
>>>From http://www.cplusplus.com/doc/information/description.html
>
> When choosing a programming language to make a project, many different
> considerations can be taken. First, one must decide what is known as
> the level of the programming language. The level determines how near to
> the hardware the programming language is. In the lower level languages,
> instructions are written thinking directly on interfacing with
> hardware, while in "high level" ones a more abstract or conceptual code
> is written.
>
> Generally, high level code is more portable, that means it can work in
> more different machines with a smaller number of modifications, whereas
> a low level language is limited by the peculiarides of the hardware
> which it was written for. Nevertheless, the advantage of low level code
> is that it is usually faster due to the fact that it is indeed written
> taking advantage of the possibilities of a specific machine.
>
> A higher or lower level of programming is to be chosen for a specific
> project depending on the type of program that is being developed. For
> example, when a hardware driver is developed for an operating system
> obviously a very low level is used for programming. While when big
> applications are developed usually a higher level is chosen, or a
> combination of critic parts written in low level languages and others
> in higher ones.
>
> (So from the above statement its clear that Object Oriented Programming
> is generally used for application type of projects)
No it is not clear, this text only talks about levels of abstraction.
There are reasons for using OOP/OBP. One reason is that the problem when
displayed/presented as interacting objects is easier to understand. Think
about it: how many drivers in fact provide a common interface? This is a
typical example of in-kernel OOP. Other examples are the memory subsystem:
it could be abstracted as a single object that initially owns all
available RAM and then gives it away in an orderly way. Mostly, this is a
case of encapsulation (which is just one facet of OOP) and something which
can also be achieved with good modules written in C. Lastly, there are
dozens of kernel-level object types inside e.g. Linux. Every time you see
a struct and a bunch of associated functions this is in fact an object. If
the struct is only available as declaration, it also has encapsulation. If
it has some function pointers or a pointer to some other struct holding
them it is an implementation of an interface, i.e. derivation and thus
OOP. If it contains a void pointer named 'private' or 'user' or such it is
to extend the data of the struct with data the particular derived
implementation needs.
Please also note that C++ is not synonymous with OOP. C++ supports OOP
(yes, to an extent that disappoints OOP purists) but doesn't mandate it.
> Some minor reasons for using C from
> http://www.linuxdevices.com/eljonline/issue07/4870s1.html
[...]
> C++'s virtues are expensive. Advanced OOP features, such as
> templates and the practice of using classes in the place of primitives,
> to name two examples, cause unacceptable code bloat.
hmmm, templates are not generally an OOP feature. Wrapping primitives can
be just as efficient as using them directly - you just need to inline
relevant accessors. Other than that, an inappropriate design will alway
suck in this or that way and you have a choice to use those features, a
fact the author of above text blissfully ignores.
> Virtual methods and polymorphism complicate runtime linking and
> require many relocations. This slows C++ application launch time
> considerably. C applications are both simple to link and amenable to
> lazy linking, so they load quickly. (For details, see Waldo Bastian's
> paper ``Making C++ Ready for the Desktop",
> http://www.suse.de/~bastian/Export/linking.txt.)
Not only that this doesn't apply to in-kernel programming (as already
pointed out), it has also ceased to be true! It was just a matter of
patching the linker to cope with whole arrays at once, as they happen with
vtables of polymorphic C++ classes, IIRC it was called the 'combreloc'
patch.
cheers
Uli
(who is surprised by the low amount of flames in this thread)
.
- References:
- Why We Use C Than C++...
- From: sonugeetha@xxxxxxxxx
- Re: Why We Use C Than C++...
- From: Richard Heathfield
- Re: Why We Use C Than C++...
- From: Walter Bright
- Re: Why We Use C Than C++...
- From: Richard Heathfield
- Re: Why We Use C Than C++...
- From: Logan Shaw
- Re: Why We Use C Than C++...
- From: Malcolm
- Re: Why We Use C Than C++...
- From: Ian
- Re: Why We Use C Than C++...
- From: Malcolm
- Re: Why We Use C Than C++...
- From: Ian
- Re: Why We Use C Than C++...
- From: Malcolm
- Re: Why We Use C Than C++...
- From: Ian Collins
- Re: Why We Use C Than C++...
- From: Malcolm
- Re: Why We Use C Than C++...
- From: Ian Collins
- Re: Why We Use C Than C++...
- From: sonugeetha@xxxxxxxxx
- Why We Use C Than C++...
- Prev by Date: Re: printf - Can't print "print\my\message"
- Next by Date: Re: printf - Can't print "print\my\message"
- Previous by thread: Re: Why We Use C Than C++...
- Next by thread: Re: Why We Use C Than C++...
- Index(es):
Relevant Pages
|