C... Why not c++?

A

Alan Balmer

Someone can exaplain me why use C instead C++? Until now i've never
found exaplanation for this.
Every project written in C on which i've worked could be written in
c++, and when in nowadays happen still to see C code i really don't
understand why the same things cannot be written in c++. Using c++
it's possble to reduce developing time achieving the same result.
Can you give me a valid reason for C?

Your premise is incorrect. I write in both C and C++, and almost
always C++ takes *more* development time, not less.
 
J

John Bode

Someone can exaplain me why use C instead C++? Until now i've never
found exaplanation for this.
Every project written in C on which i've worked could be written in
c++, and when in nowadays happen still to see C code i really don't
understand why the same things cannot be written in c++. Using c++
it's possble to reduce developing time achieving the same result.
Can you give me a valid reason for C?

1. C is a smaller language, both in terms of the grammar and
libraries and in terms of the object code that is produced. There are
times when the overhead incurred by the tools that make C++ worth
using over C (such as the STL) outweighs the convenience.

2. Most of today's senior programmers started out with C and feel
more comfortable using something they know well.

FWIW, I'm seeing less and less new development being done in C, at
least in my particular domain (i.e., server-side, non-graphical
stuff).
 
N

Neil Kurzman

Chris said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Neil Kurzman wrote:

| Few (if any) 8 bit CPUs run C++ , or ever will.

This is nonsense. The CPU will run any object code it's handed. It
doesn't matter if the code comes from a C++ compiler, a Forth compiler,
a Prolog compiler, or a human being with toggle switches and LEDs.

You might not write code in C++ for an embedded system, but there might
not be a good reason not to, either. If gcc supports the target
platform, or if you write a backend that allows it to, you automatically
get a C++ compiler that targets that system. Then it's merely a matter
of analyzing the benefits C++ brings as opposed to the downsides.

(If you say that the 8-bit chip won't be running a C++ compiler, you
should realize that 8-bit chips are rarely used as development platforms
these days. It's much, much more common to write and compile the code on
a more capable machine, test it on an emulator, and only transfer it to
the physical target system once it's been tested and debugged.)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBhf/JKxatjOtX+j0RAqGwAJ0bqpf1lBU5fb0Fc/MHvNV7HHQcQgCeOYY6
oFAYHUTae9cbbWB7kwwhC5c=
=UCwa
-----END PGP SIGNATURE-----

Yes They don't Laugh, They don't cry they just run programs.
The problem is when you 4K to 64K of code an 64K memory (256 bytes on a lot
of them)
C++ will not make the object code. PIC has several C compilers, BASIC Forth,
No C++;
8051 every thing including 1 C++ compiler. But It uses up most of the
resources.
small footprint is the key the PIC C compiler $900 US 8051 $1500
Big Money for a PC. But big savings if it fits you in the next small chip.
 
N

Neil Kurzman

Alan said:
Your premise is incorrect. I write in both C and C++, and almost
always C++ takes *more* development time, not less.

Well you must be doing it wrong C++ always takes less time and makes
better code.
Wow trolling is fun... well back to the bridge.
 
C

Chris Barts

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jacob navia wrote:
|
| Why C?
|
| Contrary to the opinions of most people in this group I think that C has
| many advantages over C++: simplicity, being the most important.

In more ways than one. I would agree with this analysis.

(Oh, and the group is comp.lang.c. I don't think too many people here
really wish they were posting to comp.lang.c++. ;))

|
| I do not think that C is a language for people that do not want to
| learn anything else (as Mr Tisdale remarks) but I am of the opinion that
| C can be used as a general purpose programming language where you can
| develop GUI application and many other kinds of software.

You can indeed develop GUI applications in C, as the Gnome project has
proven. GUI applications are more commonly developed in an
object-oriented style, however, because the OO ideas about object
frameworks seem to map well to the domain of graphical applications.

|
| C is not "object oriented" and as such, it doesn't impose a framework
| on the programmer that is implicit n the whole language. You are free,
| in C, to use the paradigm that fits the application best.

This is where I disagree. C++ is more multiparadigmatic than C, by
almost any metric. You are not required to use objects in C++. You can
write reams of C++ code without once defining a class or inheriting from
one.

Your above statement is simply wrong. That isn't a matter of opinion.

|
| I do not see C as dead and static, on the contrary, I have tried within
| the lcc-win32 compiler system to introduce extensions that make C
| programming easier without introducing undue complexity: default
| arguments, operator overloading, and some others.

And none of that is relevant to C or to this newsgroup. I doubt the next
Standards committee will look at lcc-win32 (does lcc exist on any
non-win32 platforms?) for a list of features C needs. You'd have better
luck trying to convince the gcc people that your extensions would work
well in their C frontend, simply because what's in gcc is at least known
to a very wide community.

|
| C++ is seldom portable, and even code that compiled 4 years ago will not
| compile in more recent versions of the same compiler. When you need
| software that will have to be rewritten in a few years, you can use it.
| For software that needs to run longer, C is the language of choice.

You could have said the same things about C over a decade ago, when C89
conformance was still iffy in major compilers. Conforming C++ compilers
have existed for a while now, and conforming C++ programs are guaranteed
to keep working for a long, long time. C++ written to compile on
nonstandard compilers will unfortunately become a hassle for future
programmers, but there is little reason to code that way now.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBhzxNKxatjOtX+j0RAjKxAJ9+BCcFWE4eCdJm10mMVnTBXI/Z+ACfScH1
7KlmQEWOZmvqIdfBYzLCxo8=
=5l5R
-----END PGP SIGNATURE-----
 
C

Chris Barts

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Capstar wrote:
| Chris Barts wrote:
|
|> -----BEGIN PGP SIGNED MESSAGE-----
|> Hash: SHA1
|>
|> (e-mail address removed) wrote:
|> | Simple enough, the OO & template features are not needed on some
|> | projects targeted to OS kernel development and device driver
|> | development and other low-level libraries. Moreover, most of the
|> | features require the C++ runtime library and it's too complex to
|> | implement if you write a OS kernel. Note that in WHAT language do you
|> | write the C++ runtime library?
|>
|> All of this is true enough, and those reasons can also be used to favor
|> assembly over C.
|>
|
| In some situations assembly is favored over C. But if you write assembly
| for a specific CPU, and you want to have the same program on another CPU
| you can start from scratch again. So C's portability is also a big issue.

Very, very true. With assembly code, you can only `port' the structure
and algorithms, which isn't nearly as nice as being able to reuse whole
source files.

|
|>
|> | I can't give an exact reason. As to the compiler, C is often the first
|> | language to implement and in GCC it's the background of Obj-C or C++ or
|> | Java or Ada.
|> |
|>
|> Wrong. gcc does /not/ convert everything to C. gcc has language-specific
|> frontends for /every/ language to convert the source to an internal
|> representation. (RTL, to be precise.) Read the documentation.
|
|
| I think (e-mail address removed) ment that the Obj-C/C++/Java/Ada compiler
| itself is written in C since C is often the first language a compiler is
| written for.

Hm. I didn't think of that interpretation. You're possibly correct, now
that I'm reparsing the sentence with your interpretation in mind.

And, yes, it is true that gcc itself is written in C, or at least a
variant of C that can be compiled with gcc and some other compilers.
(Which becomes a problem on MS-DOS, as gcc is the only compiler that can
compile gcc under that system. This is resolved by simply downloading
binaries the first time around.)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBhz2uKxatjOtX+j0RAi8NAJ9nEoUwo6KyaTeZfvzcolOgneLa/QCeLmgT
876a8zXXiQVOyFkkzEzGGjs=
=dXb1
-----END PGP SIGNATURE-----
 
R

Rob Thorpe

Someone can exaplain me why use C instead C++? Until now i've never
found exaplanation for this.
Every project written in C on which i've worked could be written in
c++, and when in nowadays happen still to see C code i really don't
understand why the same things cannot be written in c++. Using c++
it's possble to reduce developing time achieving the same result.
Can you give me a valid reason for C?

I'm not sure this is one topic, but anyway:

Have you ever met a programmer who knows C++, all of it? I haven't
and I don't believe they exist. All C++ programmers write in their
own particular subset of the language. Some use objects, but
otherwise use the language like C, others use the STL but little else,
still others use almost all of it.

This can make coding easier, but makes understanding the code of
others frightening.
 
D

dandelion

This can make coding easier, but makes understanding the code of
others frightening.

Depends. Well written (structured) C++ is quite easy to follow, since all
you need to know about an object is it's interface. But then again...

C offers you enough rope to hang yourself.
C++ offers a fully equipped firing squad, a last cigarette and a blindfold.
 
D

djake

Hi all,

i'm surprised about interest dedicated to the issue proposed by
me. But I think many answer are only opinion. I invite anyone to send
example or demonstration code about his theory.
For example demonstrate C++ is more fast then C, sending the
respective test code.

Still thanks for interest!!

__sysDown
 
C

CBFalconer

i'm surprised about interest dedicated to the issue proposed by
me. But I think many answer are only opinion. I invite anyone to
send example or demonstration code about his theory.
For example demonstrate C++ is more fast then C, sending the
respective test code.

No, don't. It would be off-topic. And please stop the rude
topposting.
 
M

Mike Wahler

Hi all,

i'm surprised about interest dedicated to the issue proposed by
me.

Comparing computer languages always tends to
induce religious fervor. Also note that language
comparisons are not topical here.
But I think many answer are only opinion. I invite anyone to send
example or demonstration code about his theory.
For example demonstrate C++ is more fast then C, sending the
respective test code.

Nobody can validly claim that C or C++ is 'faster' than
the other. Neither of the specifications for C or C++
make any requirements for speed. Speed is dictated by
the host platform, often aided by good quality compiler
implementations. Further aided by the programmer using
thoughtfulness when designing algorithms. E.g. one could
easily write and compile a C program which would run more
slowly than an interpreted BASIC program which does the
same things, on the same machine.

-Mike
 
M

Mike Wahler

Rob Thorpe said:
(e-mail address removed) ([email protected]) wrote in message

I'm not sure this is one topic, but anyway:

Have you ever met a programmer who knows C++, all of it?

I haven't. And imo anyone who says they do is not
being truthful. I don't think Mr. Stroustroup himself
would make such a claim.

-Mike
 
J

jacob navia

The lcc-win32 compiler compiles the gcc source code.
(11 MB)

It took me a lot of effort and now it is a standard
benchmark.

Compiling all that code without errors is quite a test
for any C compiler. I have a version (2.95.x) since years
and I compiled it with MSVC, Intel compiler, and BCC.

All produce exactly the same text file when they compile
a preprocessed source of approx 200K except borland, that
crashed a long time ago, and I haven't looked at more
recent versions.

As many GNU software packages the compiler is very difficult
to understand. I would say there are no more than a dozen
people in the world that understand all that throughout.

Compared to that, the whole code of lcc-win32 is less than
1MB, an order of magnitude simpler.

Yes, gcc does more things, and it is another scale. I just
think that an experimental compiler should be small.
 
J

jacob navia

Mike said:
Comparing computer languages always tends to
induce religious fervor. Also note that language
comparisons are not topical here.




Nobody can validly claim that C or C++ is 'faster' than
the other. Neither of the specifications for C or C++
make any requirements for speed.

I agree. And this childish excitement about "speed".

Speed for what?

If I give you a wrong result in 0.000000000001 seconds
or a correct one in 0.001 seconds which one you prefer?

We are speaking about software maintenance, software
complexity and the need (from my viewpoint) of simpler
languages that programmers can fully understand.

No one is talking "speed" of C++ since any C++ algorithm
can be written in C and the other way around. This is
ridiculous.

C++ introduces good concepts like genericity, templates,
and other stuff. The problem with it is if the cost of
those improvements is not too high. Can't we make it
simpler?

For instance we can get rid of the need for automatic
constructors/destructors with a GC!

Many C++ problems come from the fact that blindly copy
constructors, and other artificial procedures are generated
to maintain object creation/destruction in a managed
way.

The GC offers a solution to avoid the whole stuff.

Just call *yourself* new_Contact("John Doe", 35, married,2);
and leave the destructor to the GC.
 
R

Rob Thorpe

dandelion said:
Depends. Well written (structured) C++ is quite easy to follow,

Have you ever seen well structured C++? In the code I've worked on,
which I'll admit is not extensive, I haven't.
since all
you need to know about an object is it's interface.

Not to maintain it. The philosophy of some programmers is that if a
bit of their code is untidy, but has well defined outputs and inputs
then, the untidiness doesn't matter. This is fine until the code has
to be changed.
But then again...

C offers you enough rope to hang yourself.
C++ offers a fully equipped firing squad, a last cigarette and a blindfold.

Alas, something most of us know well.
 
D

dandelion

Rob Thorpe said:
"dandelion" <[email protected]> wrote in message

Have you ever seen well structured C++?
Yes.

In the code I've worked on, which I'll admit is not extensive, I haven't.
Improve.


Not to maintain it. The philosophy of some programmers is that if a
bit of their code is untidy, but has well defined outputs and inputs
then, the untidiness doesn't matter. This is fine until the code has
to be changed.

That's one of the common pitfalls. Point taken.

However, in my view, OO-design is not a replacement of the traditional
methods.

Structured programming is the foundation
Modular programming the first floor
OO-Design the attic.

So, if you want to go OO, first become expert in structured and modular
programming and *use* those techniques.
blindfold.

Alas, something most of us know well.

It's allright. Just don't shout "FIRE!". And frankly i've seen quite a lot
of *very* good C++, which ws easy to follow and modify.

And, yes... I've used C++ professionally for 6 years. The major pain in the
posterior is that it's a moving target (or has been for quite some time).
 
R

Roman Werpachowski

The only reason that C still exists is that
there are a large number of C programmers
that still aren't comfortable with C++.
There is no reason now to expect them to ever learn C++.
We are just waiting for them to retire or die.

I code my own programs for my work (I'm a physicist) and I never felt the need
to use C++. With C, I just get the job done.
 
D

djake

This demonstrate how c++ is faster then C.

On my PC C++ run 18 times more fast then C.

Look at:

http://www.research.att.com/~bs/new_learning.pdf

Try yourself the respective C and C++ code sample at pages 4 and 5.
Create a big file with a list of number to elaborate and sort and add
a logging for the time (one at the start and one at the end of main in
both files).

compile these two source files and see yourself at logs.

C++ is faster!!!
 
P

Peter Hickman

This demonstrate how c++ is faster then C.

On my PC C++ run 18 times more fast then C.

Look at:

http://www.research.att.com/~bs/new_learning.pdf

Try yourself the respective C and C++ code sample at pages 4 and 5.
Create a big file with a list of number to elaborate and sort and add
a logging for the time (one at the start and one at the end of main in
both files).

compile these two source files and see yourself at logs.

C++ is faster!!!
Perhaps you should post the sources and makefiles are I cannot even get them to
compile on my computer.
 
?

=?ISO-8859-1?Q?Bj=F8rn_Augestad?=

This demonstrate how c++ is faster then C.

On my PC C++ run 18 times more fast then C.

Look at:

http://www.research.att.com/~bs/new_learning.pdf

Try yourself the respective C and C++ code sample at pages 4 and 5.
Create a big file with a list of number to elaborate and sort and add
a logging for the time (one at the start and one at the end of main in
both files).

compile these two source files and see yourself at logs.

C++ is faster!!!

Well, after fixing several bugs in the original code, like the argv[2],
these are my results. Note that C is 15 times faster than C++. Both
programs were compiled with gcc using -O3 and -DNDEBUG.

~/tmp/cc boa@wintendo $ time ./c numbers
number of elements= 1000000, median= 1.07238e+09, mean= 1.07275e+09

real 0m2.071s
user 0m2.022s
sys 0m0.040s
~/tmp/cc boa@wintendo $ time ./c numbers
number of elements= 1000000, median= 1.07238e+09, mean= 1.07275e+09

real 0m2.053s
user 0m2.042s
sys 0m0.010s
~/tmp/cc boa@wintendo $ time ./c++ numbers
number of elements= 1000000, median= 1.07238e+09, mean= 1.07275e+09

real 0m30.852s
user 0m30.343s
sys 0m0.030s
~/tmp/cc boa@wintendo $ time ./c++ numbers
number of elements= 1000000, median= 1.07238e+09, mean= 1.07275e+09

real 0m31.954s
user 0m30.213s
sys 0m0.100s
~/tmp/cc boa@wintendo $

I guess you're not very good at neither testing nor trolling.

Bjørn
 

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
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top