Can C++ be used for system programming such as OS & DB?

R

Royt

Maybe it's a stupid question, but I really couldn't figure it out. C++
is expected to be a better C, provides compatibility with C, and is
able to do all that C can do. however, the number of projects in
sf.net written by C++ is always smaller than that of C, many people
directly turn to Java or C# after they learned C. Now that C++ is a
system programming language, it should have the capability to replace
C in many cases. We all know that the most important Operating Systems
are all written by C (the core part), and in my memory the DB engine
of Oracle is written by C (what about DB2 & sybase?). Why not use C++
to program these projects, since the management of C++ projects is
easier?

And another question. What about the runtime efficiency of C++
compared to that of C? because of the added OO features, C++ may be a
little slower. but if use C to simulate and implement the OO features
as C++ can do, will C be less efficient than C++? Can we use C++ for
the huge projects mentioned above? or those projects didn't require
any modern features, e.g. Polymorphism? (that sounds terrible)
 
A

Alf P. Steinbach

* Royt:
Maybe it's a stupid question, but I really couldn't figure it out. C++
is expected to be a better C, provides compatibility with C, and is
able to do all that C can do. however, the number of projects in
sf.net written by C++ is always smaller than that of C, many people
directly turn to Java or C# after they learned C. Now that C++ is a
system programming language, it should have the capability to replace
C in many cases.
Yes.


We all know that the most important Operating Systems
are all written by C (the core part), and in my memory the DB engine
of Oracle is written by C (what about DB2 & sybase?). Why not use C++
to program these projects, since the management of C++ projects is
easier?

An operating system is /not/ written in a single language. There's some
assembler at the innermost portions, some C, some C++ (large portions of
Windows are apparently written in C++), and even script languages. C++
has too much baggage for some parts of an operating system (mainly the
parts written in assembler), and it's too low-level for other parts
(such as those written in scripting languages), and fits quite well for
many parts in between.

And another question. What about the runtime efficiency of C++
compared to that of C? because of the added OO features, C++ may be a
little slower. but if use C to simulate and implement the OO features
as C++ can do, will C be less efficient than C++? Can we use C++ for
the huge projects mentioned above? or those projects didn't require
any modern features, e.g. Polymorphism? (that sounds terrible)

As you seem to note, if you restrict C++ to C-style, then you have the
runtime efficiency of C. If on the other hand you use C for typical C++
tasks, then you're unlikely to obtain the runtime-efficiency of C++.
Anyway, in both cases you're most likely using the wrong language for
the task: it's extremely difficult to restrict oneself to the pure C
subset of C++ (the compiler won't help), and emulating OO or template
things in C yields extremely large, complex and brittle code.
 
M

mliptak

Maybe it's a stupid question, but I really couldn't figure it out. C++
is expected to be a better C, provides compatibility with C, and is
able to do all that C can do. however, the number of projects in
sf.net written by C++ is always smaller than that of C, many people
directly turn to Java or C# after they learned C. Now that C++ is a
system programming language, it should have the capability to replace
C in many cases. We all know that the most important Operating Systems
are all written by C (the core part), and in my memory the DB engine
of Oracle is written by C (what about DB2 & sybase?). Why not use C++
to program these projects, since the management of C++ projects is
easier?

And another question. What about the runtime efficiency of C++
compared to that of C? because of the added OO features, C++ may be a
little slower. but if use C to simulate and implement the OO features
as C++ can do, will C be less efficient than C++? Can we use C++ for
the huge projects mentioned above? or those projects didn't require
any modern features, e.g. Polymorphism? (that sounds terrible)
From what I remember it has been said that the C++ compilers are buggy
in order to use them for something like OS kernel..
But it was a few years ago, maybe the statement is not true anymore.
 
J

James Kanze

Maybe it's a stupid question, but I really couldn't figure it out. C++
is expected to be a better C, provides compatibility with C, and is
able to do all that C can do. however, the number of projects in
sf.net written by C++ is always smaller than that of C, many people
directly turn to Java or C# after they learned C. Now that C++ is a
system programming language, it should have the capability to replace
C in many cases.

I can't imagine starting a new project in C, when C++ exists.
We all know that the most important Operating Systems
are all written by C (the core part),

Well, except maybe for Windows, most of the mainframes, and
significant parts of many Unixes.

Some parts of systems like Solaris are still written in C,
because they were written 15 or 20 years ago. (Other parts of
Solaris are written in C++.)
and in my memory the DB engine
of Oracle is written by C (what about DB2 & sybase?). Why not use C++
to program these projects, since the management of C++ projects is
easier?

Until recently, portability was a problem. And of course, a
company like Oracle isn't going to rewrite their entire
application just because it becomes possible to use a new
language.
And another question. What about the runtime efficiency of C++
compared to that of C?

I've not seen any difference. Typically, the two compilers
share a common back end, and when used to do the same thing,
generate exactly the same machine code. In fact, the presence
of inline functions (now supported in C as well) sometimes means
that the C++ code can be faster.
because of the added OO features, C++ may be a
little slower.

Only if you use them.

The big difference between C and C++ is that in C, you define a
struct and a set of functions to manipulate it, and you cross
your fingers that no one manipulates it otherwise. In C++, you
make the data members of the struct private, the set of
functions members, and the compiler ensures that no one
manipulates it otherwise.

Beyond that, of course, C++ supports a number of other idioms,
which may or may not be appropriate in any given application.
But the encapsulation is always appropriate, has no added
run-time cost, and justifies in itself using C++ rather than C,
even if you don't need run-time polymorphism, templates,
exceptions and all the rest.
but if use C to simulate and implement the OO features
as C++ can do, will C be less efficient than C++?

For the programmers, certainly. Probably in terms of execution
run-time as well.
Can we use C++ for
the huge projects mentioned above? or those projects didn't require
any modern features, e.g. Polymorphism? (that sounds terrible)

C++ is definitly usable, and is being used in many places, for
such things. As always, you don't have to use everything the
language offers. Only what's appropriate. (Note however that
every OS uses dynamic polymorphism at some point. A call to
read() results in significantly different code being executed if
the file descriptor designates a keyboard than when it
designates a file on disk.)
 
I

Ian Collins

James said:
Well, except maybe for Windows, most of the mainframes, and
significant parts of many Unixes.

Some parts of systems like Solaris are still written in C,
because they were written 15 or 20 years ago. (Other parts of
Solaris are written in C++.)
Only a very tiny part of the core:

cd onnv-gate/usr
find . -name "*.cc" | wc -l
65
find . -name "*.c" | wc -l
13178

About 0.5%....
 
N

Nemanja Trifunovic

are all written by C (the core part), and in my memory the DB engine
of Oracle is written by C (what about DB2 & sybase?). Why not use C++
to program these projects, since the management of C++ projects is
easier?

For historical reasons - they were started before C++ existed or at
least before it was widespread. On the other hand, BeOS was written
mostly with C++, and most of the Windows (at least user-space mode)
code is apparently written with C++, not C.
 
R

Royt

I can imagine a completely new OS kernel written in C++, But I don't
know why Java virtual machine, interpreter of Ruby and Python are all
written by C, these things appeared in 1990s, in that time C++ has
come to maturity.
 
P

Paddy3118

I can imagine a completely new OS kernel written in C++, But I don't
know why Java virtual machine, interpreter of Ruby and Python are all
written by C, these things appeared in 1990s, in that time C++ has
come to maturity.

At that time ANSI C would have been a much more mature standard than
C++. Different ANSI C compilers would be more compatible and ANSI C
would be available on a wider range of hardware than C++.

- Paddy.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top