Why do people still use C instead of C++ ?

L

Lawand

Hello.

AFAIKnew, people used to choose C over C++ as a programming language
for their projects because it posses better performance and execution
speed, but after I read this article <a herf="http://unthought.net/c++/
c_vs_c++.htmle">(C versus C++)</a> I noticed that C++ beats C in
benchmarking so, why does any programmer on earth still use/learn/
teach C instead of C++?

Shouldn't C++ have replaced C? even when developing an OS kernel or
such sensitive software.
 
I

Ian Collins

Lawand said:
Hello.

AFAIKnew, people used to choose C over C++ as a programming language
for their projects because it posses better performance and execution
speed, but after I read this article <a herf="http://unthought.net/c++/
c_vs_c++.htmle">(C versus C++)</a> I noticed that C++ beats C in
benchmarking so, why does any programmer on earth still use/learn/
teach C instead of C++?

Shouldn't C++ have replaced C? even when developing an OS kernel or
such sensitive software.

Have you ever tried to find a C++ compiler for a PIC?
 
P

paulkp

benchmarking so, why does any programmer on earth still use/learn/
teach C instead of C++?

For many reasons. Usually people have irrational reasons for
using thing X. That's how people are. Even I was like that and
I'm a genius.
 
L

Lawand

Have you ever tried to find a C++ compiler for a PIC?

That's something I haven't thought of, but let's say there isn't, in
that case, is the lack of C++ compilers for micro controllers means
that there can't be, or means that there shouldn't be.
Or maybe they didn't design one because it's complex.

Anyway, it's not what I am wondering about, what I don't know the
reason of, is writing code (for CPUs, not micro controllers) such as
OS kernels in C instead of C++.
I mean, why bother using C where there exist a more programmer
efficient and faster counterpart, the C++ ?
 
M

maverik

Hello.

AFAIKnew, people used to choose C over C++ as a programming language
for their projects because it posses better performance and execution
speed, but after I read this article <a herf="http://unthought.net/c++/
c_vs_c++.htmle">(C versus C++)</a> I noticed that C++ beats C in
benchmarking so, why does any programmer on earth still use/learn/
teach C instead of C++?

Shouldn't C++ have replaced C? even when developing an OS kernel or
such sensitive software.

Probably, it's better to use a tool that is better suited to your
task. So it depends.

For example, you want to eat a plate of soup. You have 2 ways: you can
use a spoon or an excavator shovel. It is well known that shovel more
powerful tool for rake and beats the spoon. So, should you use
excavator shovel? Probably not. And why? Because, a spoon can solve
this problem more efficiently that the excavator shovel.
 
J

jason.cipriani

Hello.

AFAIKnew, people used to choose C over C++ as a programming language
for their projects because it posses better performance and execution
speed, but after I read this article <a herf="http://unthought.net/c++/
c_vs_c++.htmle">(C versus C++)</a> I noticed that C++ beats C in
benchmarking so, why does any programmer on earth still use/learn/
teach C instead of C++?

You must not have read the article, or you're here trolling. It was an
RB-tree implemented in C++ vs. a hash table implemented in C. At the
bottom of the article, it clearly states:

"But this benchmark is no good for the purpose of the "C versus C++"
argument - it's two completely different approaches that yield
completely different results, for reasons that have nothing to do with
the languages used."

There's not, actually, a difference in performance between the two.
They're both compiled to native code, frequently by a compiler that
handles both languages at once, using the same logic for compilation.
Check out the code your compiler generates. A performance difference
between the two languages wouldn't actually make any sense. Any byte
code you produce from C++ can be produced almost identically with C,
except it will take you a heck of a lot longer to express it in C. The
only big difference in "performance" is your algorithms, as shown in
the article.

I guess you missed that part?

Shouldn't C++ have replaced C? even when developing an OS kernel or
such sensitive software.

You're welcome to port the existing Linux kernel (for example), to C+
+. While you're working on it, you can reflect on why nobody else has
done it yet.

Most of the time the reasons are that you are maintaining code written
in C or you are on a platform that nobody has bothered to write a C++
compiler for (e.g. PIC). A lot of programmers raised on C will stick
to C because it's what they know, with logic like "well if you're not
going to use the features of C++, you might as well use C". An
experienced C programmer has techniques that he's comfortable with and
simply doesn't see a need to switch. I guess that's reasonable, who
knows (or cares)?

C++ also took a bit of time to become accepted because early (e.g. mid
90's) compilers were strange and quirky. This also probably left a bad
taste in the mouth of those who attempted to learn it at the time.
Most C++ compilers are mature enough now that it's no longer an issue.


HTH, and next time read the article.
Jason
 
J

jason.cipriani

But let's say you regularly eat a plate of soup at a place where, for some
odd reason, they don't provide utensils. You also sometimes do shoveling
when you're out. You'd bring a spoon and the excavator shovel, and use the
spoon for the soup. C++ gives you both, and you don't have to use anything
more than the spoon when metaphorically eating soup. You always have the
option of using a more fancy spoon, also part of C++, building your own
spoon, or (mis)using the shovel. The choice is yours. So why would C++ be
ill-suited in a situation where C is suited?

This is a really silly analogy that shouldn't have been made in the
first place. Not quite sure why programmers are so keen on ridiculous
analogies all the time. It's not even necessary, and doesn't make all
that much sense. "C++ gives you both a spoon AND a shovel but C only
gives you a spoon OR a shovel" isn't really a compelling statement
of... anything at all. Sorry.

Mentioning the word "efficient", in the context of performance, is
also irrelevant. The languages are the same and the article does not
actually attempt to show a "performance" difference between the two
(go read it).

The article does explain that C is more verbose for certain tasks. The
compiled code is not going to differ that much between the two. You
can express the same programs with both, you just have to type more
with C sometimes.

HTH,
Jason
 
L

Lawand

You must not have read the article, or you're here trolling. It was an
RB-tree implemented in C++ vs. a hash table implemented in C. At the
bottom of the article, it clearly states:

"But this benchmark is no good for the purpose of the "C versus C++"
argument - it's two completely different approaches that yield
completely different results, for reasons that have nothing to do with
the languages used."

There's not, actually, a difference in performance between the two.
They're both compiled to native code, frequently by a compiler that
handles both languages at once, using the same logic for compilation.
Check out the code your compiler generates. A performance difference
between the two languages wouldn't actually make any sense. Any byte
code you produce from C++ can be produced almost identically with C,
except it will take you a heck of a lot longer to express it in C. The
only big difference in "performance" is your algorithms, as shown in
the article.

I guess you missed that part?


You're welcome to port the existing Linux kernel (for example), to C+
+. While you're working on it, you can reflect on why nobody else has
done it yet.

Most of the time the reasons are that you are maintaining code written
in C or you are on a platform that nobody has bothered to write a C++
compiler for (e.g. PIC). A lot of programmers raised on C will stick
to C because it's what they know, with logic like "well if you're not
going to use the features of C++, you might as well use C". An
experienced C programmer has techniques that he's comfortable with and
simply doesn't see a need to switch. I guess that's reasonable, who
knows (or cares)?

C++ also took a bit of time to become accepted because early (e.g. mid
90's) compilers were strange and quirky. This also probably left a bad
taste in the mouth of those who attempted to learn it at the time.
Most C++ compilers are mature enough now that it's no longer an issue.

HTH, and next time read the article.
Jason

Calm down :)

Now, are you saying that, as a conclusion, C++ is better than C
(because there's no difference in performance, yet C++ has more
features), but programmers still use C just because they're used to?

And in that case, all newbies should be advised to learn C++, right?
 
R

Rui Maciel

Lawand said:
Calm down :)

Trolls don't usually make people get calmer.

Now, are you saying that, as a conclusion, C++ is better than C
(because there's no difference in performance, yet C++ has more
features), but programmers still use C just because they're used to?

You are putting words into jason's mouth. You failed to read the article and jason pointed out that even the article clearly stated that their benchmarks could not be used to compare the languages in those silly and pointless "language A Vs language B" discussions, which was what you promptly did.

Moreover, C and C++ are two different languages that scratch different itches. The only person that keeps forcing the "language A is better than language B" conclusion is, well... you.


Rui Maciel
 
L

Laurent Deniau

Calm down :)

Now, are you saying that, as a conclusion, C++ is better than C
(because there's no difference in performance, yet C++ has more
features), but programmers still use C just because they're used to?

And in that case, all newbies should be advised to learn C++, right?

C++ is not a super set of C and is much more complex which means that
"average" C++ programmers may have some difficulty to predict the
behavior of their code. There is also things which are "easy" to do in
C and nearly impossible in C++. I have been using C++ from 1989 to
2006 and switch back to C for this reason once I found the programming
techniques that fit my needs. Before doing the switch, I used (and
abused) templates and I studied in depth the C++ object model to
understand what I could(n't) do. As already said, the best is to use
the language that fits your needs.

a+, ld.
 
B

Bo Persson

Lawand said:
That's something I haven't thought of, but let's say there isn't, in
that case, is the lack of C++ compilers for micro controllers means
that there can't be, or means that there shouldn't be.
Or maybe they didn't design one because it's complex.

Anyway, it's not what I am wondering about, what I don't know the
reason of, is writing code (for CPUs, not micro controllers) such as
OS kernels in C instead of C++.
I mean, why bother using C where there exist a more programmer
efficient and faster counterpart, the C++ ?

There are OS kernels written in C++, like Symbian, so it is very
possible.

The main reason for the major operating systems is that they have been
around since before C++ became a viable option. They were started out
in C, and has kept this tradition.


Bo Persson
 
B

Bo Persson

Laurent said:
C++ is not a super set of C and is much more complex which means
that "average" C++ programmers may have some difficulty to predict
the behavior of their code. There is also things which are "easy"
to do in C and nearly impossible in C++.


I am really curious here - wanna give some examples?


Bo Persson
 
J

jason.cipriani

Now, are you saying that, as a conclusion, C++ is better than C
(because there's no difference in performance, yet C++ has more
features), but programmers still use C just because they're used to?
No.

And in that case, all newbies should be advised to learn C++, right?

No.

It seems you read my post about as closely as you read that article.
Jason
 
P

perlwhiz

Shouldn't C++ have replaced C? even when developing an OS kernel or
such sensitive software.

I'm reminded of Linus Torvalds' big rant against C++ last year. Google
"linus torvalds c++" and read his posts at gmane.org for another
opinion.
 
J

James Kanze

That's something I haven't thought of, but let's say there
isn't, in that case, is the lack of C++ compilers for micro
controllers means that there can't be, or means that there
shouldn't be. Or maybe they didn't design one because it's
complex.

Or because their competitors didn't, so they don't feel the need
to.
Anyway, it's not what I am wondering about, what I don't know
the reason of, is writing code (for CPUs, not micro
controllers) such as OS kernels in C instead of C++.

Most OS kernels for modern general purpose machines do contain
quite a bit of C++. Significant parts of the many of the
kernels, however, were written before C++ was generally
available.
I mean, why bother using C where there exist a more programmer
efficient and faster counterpart, the C++ ?

Mainly habit and existing code.
 
R

Rolf Magnus

Laurent said:
C++ is not a super set of C

It can be used as one.
and is much more complex which means that "average" C++ programmers may
have some difficulty to predict the behavior of their code. There is also
things which are "easy" to do in C and nearly impossible in C++.

Which would that be? Most C code can be put through a C++ compiler with only
a few minor changes.
I have been using C++ from 1989 to 2006 and switch back to C for this
reason once I found the programming techniques that fit my needs. Before
doing the switch, I used (and abused) templates and I studied in depth the
C++ object model to understand what I could(n't) do. As already said, the
best is to use the language that fits your needs.

I can see uses of templates even down to the smallest microcontroller
devices (and have actually used them there).
 
L

Laurent Deniau

I am really curious here  - wanna give some examples?

google for "C Object System" or go to sourceforge. COS itself cannot
be implemented in C++ AFAIK and it would be very complex to implement
even by a C++ compiler ("The good is the enemy of the best"). It
provides the dynamic counterpart of the template, that is multi-
methods which I consider to be more important than templates.
Obviously, if I could have both, it would be even better. Another
feature that I consider very important is the (generic) delegation and
it can only be implemented on top of messages.

a+, ld.
 
L

Laurent Deniau

It can be used as one.


Which would that be? Most C code can be put through a C++ compiler with only
a few minor changes.

I would be very interested (honestly) by the "few minor changes" to
apply to COS (C Object System) to be able to compile it with a C++
compiler. It compiles with a C99 compiler or even with a C99
(standalone) preprocessor and a C89 compiler.
I can see uses of templates even down to the smallest microcontroller
devices (and have actually used them there).

I didn't say that you can't or it's useless. I just say that I tried
to implement some features (e.g. multi-methods, messages) which I
consider today to be very important in a language and failed to do it
in C++ while it was relatively easy to do in C.

a+, ld.
 
J

jason.cipriani

I would be very interested (honestly) by the "few minor changes" to
apply to COS (C Object System) to be able to compile it with a C++
compiler. It compiles with a C99 compiler or even with a C99
(standalone) preprocessor and a C89 compiler.


I had wanted to take a stab at it, but:


1. COS is not actually available on SourceForce except through CVS.
Not very convenient.

2. The COS Makefiles do not build. It appears you used something like
autoconf but did not actually include a configure script in CVS. The
compilation instructions in your README are incorrect. After looking
for the source of the problem and seeing the number of environment
variables that were not defined (e.g. everything checked for by the
'prologue' include file), I gave up.

3. While it's certainly an interesting project, you seem to have
reinvented a serious wheel. If a developer used COS in an application,
then more likely there were better tools for that developer's job than
C in the first place.

I didn't say that you can't or it's useless. I just say that I tried
to implement some features (e.g. multi-methods, messages) which I
consider today to be very important in a language and failed to do it
in C++ while it was relatively easy to do in C.


Why did you fail to do it in C++? What specific problems are you
referring to? Issues with... type checking or something? It's fairly
straightforward to compile C with a C++ compiler; most of the changes
involve adding explicit casts and changing names that are now C++
keywords (e.g. "class").

Most issues are described here: http://docs.hp.com/en/92501-90029/ch01s03.html
, search the page for "changing your C programs to C++".

C does not have support for multi-methods, nor does C++, in both
languages you have to emulate them some other way. I can certainly
imagine various schemes for implementing them in C++; they are
probably similar to what you did in C. What is it about C++ that you
found to be a barrier to implementing these? There are plenty of ways
to do runtime type checking in C++...

Same deal with messaging systems, which are just as trivial to
implement in C++ as they are in C.


Jason

P.S. Just to set the tone, I don't have a problem with C at all, and
still use it for some applications. Mostly I'm wondering if you've
actually been having issues with C++, or if the issues are because
your implementation attempts failed for other reasons.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top