Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Ok Enough Which is faster C or C++
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 126 - 150 of 228 - Expand all  -  Translate all to Translated (View all originals) < Older  Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dean Smith  
View profile  
 More options Mar 16 2002, 5:30 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Dean Smith <dsmi...@yahoo.com>
Date: Sat, 16 Mar 2002 23:25:37 +0100
Local: Sat, Mar 16 2002 5:25 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
In article <a6ohei$4v...@cascade.cs.ubc.ca>, gill...@cs.ubc.ca says...

You've hit the nail right on the head with this post! Good analogy too
:).

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Slater  
View profile  
 More options Mar 16 2002, 6:11 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: lesse...@hotmail.com (John Slater)
Date: 16 Mar 2002 15:11:44 -0800
Local: Sat, Mar 16 2002 6:11 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Bart Kowalski" <m...@nospam.com> wrote in message <news:ymWj8.19056$Yg2.2167677@news20.bellglobal.com>...
> "Donald Gillies" <gill...@cs.ubc.ca> wrote in message
> news:a6ohei$4ve$1@cascade.cs.ubc.ca...

> > Unfortunately, when you criticize C++ in any way, in any forum, you
> > are preaching christianity to the muslims.  Then you can sit back and
> > watch the sparks fly as these muslim C++ programmers impale themselves
> > on unsupportable statements about software engineering, compilers,
> > languages, complexity of large systems, etc.

> You have just made the public confession of being a troll. Expect many
> people to ignore you permanently.

> Bart.

Whats wrong Bart, have you recognized yourself in the above paragraph?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chelly  
View profile  
 More options Mar 16 2002, 7:43 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: postmast.root.admi....@iname.com (Chelly)
Date: Sun, 17 Mar 2002 00:45:32 GMT
Local: Sat, Mar 16 2002 7:45 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
In article <3C90BC56.878E6...@hobbiton.org>, NotFound

<blas...@hobbiton.org> wrote:
> > In other words, the standard library is faster than what we
> > write. Thus a bigger standard library will lead to faster code. C++

> I disagree. The advantage of the standard library is not the speed at
> runtime, is that it is already written and tested. The argument "You
> can't write something equally fast" is only valid for beginners.

Can't there be more than one advantage to using the standard libraries
over custom user code? I'm not sure what "the" advantage means, anyway.

Libraries allow increased resources to be invested in their production,
due to a larger number of users (as compared to single-use non-library
code). These extra resources can be used to make the library more robust,
easier to use, more efficient, smaller, easily portable, etc.

The standard libraries are some of the most widely used, due to their
inclusion with virtually every compiler. Since the interface is largely
fixed, resources can go mainly to robustness and efficiency. I'd expect
speed-critical portions of the standard libraries to be quite optimized.
These include memory copy, basic string operations, freestore management,
and I/O. Since the standard library is often supplied by the compiler
vendor, architecture-specific optimizations are sometimes present
(especially in the memory/string functions).

As far as writing something as fast as the standard library, the issue is
the amount of efficiency you can get for a moderate cost. Given unlimited
resources, you can compete with any library. Given a practical amount of
resources, it's often a win to use the standard library.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NotFound  
View profile  
 More options Mar 16 2002, 8:27 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: NotFound <blas...@hobbiton.org>
Date: Sun, 17 Mar 2002 01:56:48 +0100
Local: Sat, Mar 16 2002 7:56 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

> > I disagree. The advantage of the standard library is not the speed at
> > runtime, is that it is already written and tested. The argument "You
> > can't write something equally fast" is only valid for beginners.
> Can't there be more than one advantage to using the standard libraries
> over custom user code? I'm not sure what "the" advantage means, anyway.

Well, say the main advantage.

> The standard libraries are some of the most widely used, due to their
> inclusion with virtually every compiler. Since the interface is largely
> fixed, resources can go mainly to robustness and efficiency. I'd expect
> speed-critical portions of the standard libraries to be quite optimized.

True, but many optimizations are of public knowledge and a motivated
programmer can do the same.

> As far as writing something as fast as the standard library, the issue is
> the amount of efficiency you can get for a moderate cost. Given unlimited
> resources, you can compete with any library. Given a practical amount of
> resources, it's often a win to use the standard library.

I agree with this, but i think the reason is more exactly than one can
emply the time in optmize other parts of the program rather than on beat
the standard library and possibly obtain more benfits.

Regards.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bart Kowalski  
View profile  
 More options Mar 17 2002, 12:20 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
Followup-To: alt.flame
From: "Bart Kowalski" <m...@nospam.com>
Date: Sun, 17 Mar 2002 00:25:18 -0500
Local: Sun, Mar 17 2002 12:25 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
"John Slater" <lesse...@hotmail.com> wrote in message

news:e0821c1d.0203161511.1833aab4@posting.google.com...
> "Bart Kowalski" <m...@nospam.com> wrote in message

<news:ymWj8.19056$Yg2.2167677@news20.bellglobal.com>...

> > "Donald Gillies" <gill...@cs.ubc.ca> wrote in message
> > news:a6ohei$4ve$1@cascade.cs.ubc.ca...

> > > Unfortunately, when you criticize C++ in any way, in any forum, you
> > > are preaching christianity to the muslims.  Then you can sit back and
> > > watch the sparks fly as these muslim C++ programmers impale themselves
> > > on unsupportable statements about software engineering, compilers,
> > > languages, complexity of large systems, etc.

> > You have just made the public confession of being a troll. Expect many
> > people to ignore you permanently.

> Whats wrong Bart, have you recognized yourself in the above paragraph?

I couldn't care less for this debate, nor for your flamebait. Follow-
ups set.

Bart.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chelly  
View profile  
 More options Mar 17 2002, 1:22 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: postmast.root.admi....@iname.com (Chelly)
Date: Sun, 17 Mar 2002 06:21:49 GMT
Local: Sun, Mar 17 2002 1:21 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
In article <3C93E9D0.AD9E2...@hobbiton.org>, NotFound

<blas...@hobbiton.org> wrote:
> > > I disagree. The advantage of the standard library is not the speed at
> > > runtime, is that it is already written and tested. The argument "You
> > > can't write something equally fast" is only valid for beginners.

> > Can't there be more than one advantage to using the standard libraries
> > over custom user code? I'm not sure what "the" advantage means, anyway.

> Well, say the main advantage.

I apologize for the above. I see your point. Having robust libraries is
primary. They will be reasonably optimized anyway.

[snip]

> > As far as writing something as fast as the standard library, the issue is
> > the amount of efficiency you can get for a moderate cost. Given unlimited
> > resources, you can compete with any library. Given a practical amount of
> > resources, it's often a win to use the standard library.

> I agree with this, but i think the reason is more exactly than one can
> emply the time in optmize other parts of the program rather than on beat
> the standard library and possibly obtain more benfits.

Good point. The implementor of the program has access to the "top" of the
system, allowing them to optimize the hot spot wherever it is (if it's in
the lib they can write an optimized replacement and use that). The
implementor of the standard library can only meaningfully optimize when
the hot spot lands in the library.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Isotton  
View profile  
 More options Mar 17 2002, 6:04 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Aaron Isotton <aa...@please-no-spam.isotton.com>
Date: 17 Mar 2002 00:49:30 +0100
Local: Sat, Mar 16 2002 6:49 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

NotFound <blas...@hobbiton.org> writes:
> > In other words, the standard library is faster than what we
> > write. Thus a bigger standard library will lead to faster code. C++

> I disagree. The advantage of the standard library is not the speed at
> runtime, is that it is already written and tested. The argument "You
> can't write something equally fast" is only valid for beginners.

I agree with your statement that the main advantage of the standard
library is its speed and its stability. But you cannot always write an
equally fast alternative to its routines in standard C++, because they
might be implemented in assembler. And hand-crafted assembler written
by skilled programmers is still faster than most output of nowadays'
compilers. The main problem is that the standard library is written
specifically for a platform, while portable code isn't.

For an example, you can search this ng for a few hundred posts about
'FastString' by Peter Olcott. Although 99% if not more of those
threads are total crap, one interesting fact which emerges is that
Olcott's own standard C++ (or C for that matter) kind-of
implementation was still quite a lot slower than the standard
library's memcpy. This may be a function where optimization is
especially important, but there are others as well. One example might
be a deque, which is generally implemented as a bunch of blocks; those
blocks might have a certain size due to the platform's memory access
methods, which can not be detected by standard C++.

> Regards.

Aaron

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NotFound  
View profile  
 More options Mar 17 2002, 10:12 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: NotFound <blas...@hobbiton.org>
Date: Sun, 17 Mar 2002 03:29:06 +0100
Local: Sat, Mar 16 2002 9:29 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

> I agree with your statement that the main advantage of the standard
> library is its speed and its stability. But you cannot always write an
> equally fast alternative to its routines in standard C++, because they
> might be implemented in assembler. And hand-crafted assembler written

You cannot write it in standard C++, i agree, but out of this newsgroup
(comp.lang.c++) is not the only way of write code ;) If the need for
speed in important one can use platform especific extensions,
assembler... and achieve the portability with conditional compilation
for each platform required. That need time and resources and is not
always an alternative, of course.

> For an example, you can search this ng for a few hundred posts about
> 'FastString' by Peter Olcott. Although 99% if not more of those

Aaaaahhhh!!!! Please, not, i don't want to read Olcott's inevntions
again :D

> library's memcpy. This may be a function where optimization is
> especially important, but there are others as well. One example might

And there are others cases when not, i am sure. And in Olcott's threads
I remember read apropos of std::string that specific specialization for
basic_string<char> is not used almost in one compiler for the reason
that stability is more important than speed for the customers. Then one
cannot expect that the standard library is optimized in all cases.

Regards.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NotFound  
View profile  
 More options Mar 17 2002, 10:12 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: NotFound <blas...@hobbiton.org>
Date: Sun, 17 Mar 2002 03:33:07 +0100
Local: Sat, Mar 16 2002 9:33 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

> > I agree with this, but i think the reason is more exactly than one can
> > emply the time in optmize other parts of the program rather than on beat
> > the standard library and possibly obtain more benfits.
> Good point. The implementor of the program has access to the "top" of the
> system, allowing them to optimize the hot spot wherever it is (if it's in
> the lib they can write an optimized replacement and use that). The

Exactly. The point "The standard library is fast enough" is a
generalization but we can't forget the exceptions.

Regards.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Minti  
View profile  
 More options Mar 17 2002, 12:58 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: mintispambl...@yahoo.com (Minti)
Date: 17 Mar 2002 09:58:14 -0800
Local: Sun, Mar 17 2002 12:58 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Lame C++" can bootstarp because if does not compile it does not show
the message.
Did you mean that Lame C++ was previously built on some other
compiler, because then the fault can be in the other compiler, so why
blame Lame C++.

> > > In theory, no, it can't. In practice, yes, we must look at real world
> > > implementations when discussing real world implementation issues.
> > > Performance is not a language issue.

> > Lets decide first if we discuss for our PC or some embedded device.

> Well, that's up to the OP. He actually asked which was faster, C or C++.
> IIRC he didn't specify platforms, implementations, or test programs.
> Therefore, of course, the question is meaningless.

My main reason for asking was that Ioannis said that working with
something called container or box[Sorry I forget these things] would
@not@ make my code slower if instead I used the variable sized arrays
of C99, I disagree mainly because it depends upon what I need, if I
need only to have variable sized arrays, then they would under most
circumstances provide better performence.
What do you think?
Also what about the virtual functions I hear that they make the
performence slower.

[BIG SNIP]

> Remember those programs for printing a string in C and in C++? I tested
> those for speed, using Cygwin's time utility, and found the C code to be
> significantly faster. Try it yourself.

The equivalent of a code printing something like

#include <stdio.h>

int main()
{
        printf("Choo Mantar");

}

in C++ would be

#include <cstdio>
using std::cout

int main()
{
        printf("Choo Mantar");

}

I have quite very much times considered using

std::cout << "This " << "is" << "         ";

To be slower than

printf("This is            ");

Thanks for showing. However how general is this observation?

> <snip>

> You've already said that no C++ code can be slower or bigger than the
> equivalent C code, and I've already performed measurements which show
> that that is not the case.

> APL is a programming language which uses its own weird character set -
> it's intended for mathematicians, mainly, and is considered by many to
> be a "write-only" language.

How do you define "Write-only" language.

P.S. I disagree with the type of arguments that you give like Zog C++
inserting a delay, it would be nice if you could not waste others time
with these arguements. Thanks.

PPS Somewhere you mentioned that the only way to win this arguement is
not to participate. I realised that and did not post[Frankly I had
other reasons also], But what about you, you also seem to be with the
stand that C is always faster than C++.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Al Dunbar  
View profile  
 More options Mar 17 2002, 2:03 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: "Al Dunbar" <LuigiDun...@hotmail.com>
Date: Sun, 17 Mar 2002 19:02:57 GMT
Local: Sun, Mar 17 2002 2:02 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Minti" <mintispambl...@yahoo.com> wrote in message

news:51d20cd0.0203170958.517da407@posting.google.com...
> Richard Heathfield <bin...@eton.powernet.co.uk> wrote in message

<news:3C91B1C1.7C16EE5C@eton.powernet.co.uk>...

> > Ioannis Vranos wrote:

> > > "Richard Heathfield" <bin...@eton.powernet.co.uk> wrote in message
> > > news:3C8F8ACE.9138276C@eton.powernet.co.uk...
> > > > As a proof, by the way, that MSVC++ is /not/ the most broken C++
> > > > implementation, here's an even more broken C++ implementation:

<Snip>

> > > > This implementation doesn't bootstrap well, of course.

> > > What does "bootstrap" mean?

> > In this context, bootstrapping is the "break-even" point for a compiler
> > - the point at which it can compile its own source code. Clearly,
> > LameC++ can't.

> "Lame C++" can bootstarp because if does not compile it does not show
> the message.
> Did you mean that Lame C++ was previously built on some other
> compiler, because then the fault can be in the other compiler, so why
> blame Lame C++.

Don't blame the other compiler either, blame those who developed Lame C++.

I don't get it, any fault found in something I produce I can blame on the
development tools. How then do I react to accolades?

/Al


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ioannis Vranos  
View profile  
 More options Mar 17 2002, 5:21 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: "Ioannis Vranos" <noi...@no.spam.yahoo.com>
Date: Mon, 18 Mar 2002 00:21:15 +0200
Local: Sun, Mar 17 2002 5:21 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
"Minti" <mintispambl...@yahoo.com> wrote in message

news:51d20cd0.0203170958.517da407@posting.google.com...

> "Lame C++" can bootstarp because if does not compile it does not show
> the message.
> Did you mean that Lame C++ was previously built on some other
> compiler, because then the fault can be in the other compiler, so why
> blame Lame C++.

That's a good theory. :)

> My main reason for asking was that Ioannis said that working with
> something called container or box[Sorry I forget these things] would
> @not@ make my code slower if instead I used the variable sized arrays
> of C99, I disagree mainly because it depends upon what I need, if I
> need only to have variable sized arrays, then they would under most
> circumstances provide better performence.

C++ containers aren't slower, the only thing they have is space cost.
They do hot have time cost because their member functions are inlined.
An example, std::string vs char * in my tests:

http://users.forthnet.gr/ath/jvr/c++faq.htm

> What do you think?
> Also what about the virtual functions I hear that they make the
> performence slower.

They have a slightly more cost than conventional member functions but in
the context they are used that is expected anyway (e.g. the example of
Richard Heathfield where he said he likes to store keeping information
himeself).

From my measurements i have found no additional time cost between cout
in printf in both my compilers.

> PPS Somewhere you mentioned that the only way to win this arguement is
> not to participate. I realised that and did not post[Frankly I had
> other reasons also], But what about you, you also seem to be with the
> stand that C is always faster than C++.

See it from a philosophical view. Almost the whole C89 is a subset of
C++, so how can it be faster than C++? :)

--
Ioannis

* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Doenges  
View profile  
 More options Mar 18 2002, 2:59 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Eric Doenges <Eric.Doen...@lpr.ei.tum.de>
Date: 18 Mar 02 07:48:10 GMT
Local: Mon, Mar 18 2002 2:48 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Ioannis Vranos" <noi...@no.spam.yahoo.com> writes:
>> > C:\c>temp
>> > Hello World!
>> > printf() took 0 clock_t

>> > Hello World!
>> > cout took 0 clock_t

>> > and MINGW32's clock_t is msecs so they have indeed the same speed.

All that you have shown is that both methods of doing output take less
than the minimum measureable about of time on your system. Frankly, I
wonder how anyone is supposed to take your arguments seriously when
you are measuring the speed of a single function call in milliseconds.
To do a more meaningfull test, either use the Pentium's timestamp
counter, or measure multiple function calls; better yet use both.
--
________________________________________________________________________
Dipl.-Ing. Eric Doenges                         http://www.rcs.ei.tum.de
Institute for Real-Time Computer Systems (RCS)      fon +49-89-289-23590
Technische Universitaet Muenchen, D-80290 Muenchen  fax +49-89-289-23555

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Heathfield  
View profile  
 More options Mar 18 2002, 4:36 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Richard Heathfield <bin...@eton.powernet.co.uk>
Date: Mon, 18 Mar 2002 09:00:40 +0000
Local: Mon, Mar 18 2002 4:00 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

No, although they have certain characteristics in common.

<snip>

> I'll come back to inlines in a moment. With templates, you only get
> one specialised version of a templatised class or function per type,
> no matter how many times each type is used.

I know, but of course you *do* get one separate specialised version for
each *type*, which was all I intended to claim. My apologies if I didn't
put it clearly enough.

<snip>

--
Richard Heathfield : bin...@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Heathfield  
View profile  
 More options Mar 18 2002, 4:36 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Richard Heathfield <bin...@eton.powernet.co.uk>
Date: Mon, 18 Mar 2002 09:13:33 +0000
Local: Mon, Mar 18 2002 4:13 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

Minti wrote:

> Richard Heathfield <bin...@eton.powernet.co.uk> wrote in message <news:3C91B1C1.7C16EE5C@eton.powernet.co.uk>...
> > > > This implementation doesn't bootstrap well, of course.

> > > What does "bootstrap" mean?

> > In this context, bootstrapping is the "break-even" point for a compiler
> > - the point at which it can compile its own source code. Clearly,
> > LameC++ can't.

> "Lame C++" can bootstarp because if does not compile it does not show
> the message.

If it can't compile itself, it can't bootstrap. And it's quite clear
that it can't compile itself.

> Did you mean that Lame C++ was previously built on some other
> compiler, because then the fault can be in the other compiler, so why
> blame Lame C++.

Your question is based on such a fundamental misunderstanding of my
original point that it's hard to know where to begin answering. Instead,
allow me to re-state the original point.

Ioannis Vranos claimed that MSVC++ was the most broken C++ compiler out
there (or some similar words). I showed him that this is not true, by
providing an example of an even more broken C++ compiler - one that is
so broken it can't even compile a single C++ program. The bootstrapping
joke was just that - a joke.

I think that the question is flawed. The speed of your program depends
far more on your choosing appropriate algorithms and implementing them
well, than it does on your choice of language. Choose the language you
like best, but don't try to pretend that it's faster, or slower, than
the alternative choice.

> Also what about the virtual functions I hear that they make the
> performence slower.

If you choose the right algorithms, the performance hit of virtual
functions is unlikely to be significant enough to matter.

<snip>

> How do you define "Write-only" language.

A language in which typical programs are very hard to read.

> P.S. I disagree with the type of arguments that you give like Zog C++
> inserting a delay, it would be nice if you could not waste others time
> with these arguements. Thanks.

My point in using that illustration was that implementations, not
languages, determine performance. If you don't want to hear the answer,
don't ask the question.

> PPS Somewhere you mentioned that the only way to win this arguement is
> not to participate. I realised that and did not post[Frankly I had
> other reasons also], But what about you, you also seem to be with the
> stand that C is always faster than C++.

No, I take the position that implementations, not languages, determine
performance, but that there are some aspects inherent in C++ which will
tend to make it marginally slower than C in some circumstances.
Conversely, there are some situations in which C++ will be faster. It
depends on many factors, of which the overwhelming ones are (1) the
program and (2) the implementation. Your choice of language matters much
less than either of these two factors.

--
Richard Heathfield : bin...@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Heathfield  
View profile  
 More options Mar 18 2002, 4:36 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: Richard Heathfield <bin...@eton.powernet.co.uk>
Date: Mon, 18 Mar 2002 09:20:08 +0000
Local: Mon, Mar 18 2002 4:20 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

Ioannis Vranos wrote:

<snip>

> See it from a philosophical view. Almost the whole C89 is a subset of
> C++, so how can it be faster than C++? :)

A car is a subset of a car+caravan. The car is faster.

This analogy *doesn't* show that C is faster than C++. It only shows
that it is not illogical for the possibility to exist.

--
Richard Heathfield : bin...@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Embedded C or C++" by Jonathan Kirwan
Jonathan Kirwan  
View profile  
(1 user)  More options Mar 18 2002, 5:05 am
Newsgroups: comp.arch.embedded
From: Jonathan Kirwan <jkir...@easystreet.com>
Date: Mon, 18 Mar 2002 10:05:31 GMT
Local: Mon, Mar 18 2002 5:05 am
Subject: Embedded C or C++
Intro
-----

A thread has been cross-posted on four groups on the subject of C or
C++.  As I'm only writing as an embedded programmer, I wanted to avoid
adding to that cross-posting fray.  I'm posting this only in CAE.

I should say what my biases are before I speak.  I'm not a C expert,
though I've been using C since 1978 and have written a working, toy C
compiler.  I'm not a C++ expert, though I've been using C++ since 1989
for Windows programming.

What I care about is very different from what many C++ programmers
care about, because my area of designing and coding small embedded
systems does NOT include any Windows or Linux programming.  (That is
not to say I don't program on Windows or Linux, just that I don't
program them for embedded products.)  And keep in mind that I'm
talking about only one facet of my programming experience -- the
embedded facet.  And that my embedded universe is NOT the same as the
embedded universe as a whole -- again, it is only a subset of that,
too.

I'm very interested in using C++ in my projects.  I'm just quite
skeptical, for a variety of reasons, about using one.

My World and Welcome To It
--------------------------

My world includes processors with as little as 500 instructions of
code space, or so.  Some of my applications only require 1/10th of
that, to be honest.  I rarely, very rarely get to use a processor with
more than 32k instructions available.  The RAM is often limited to a
few tens of bytes and rarely gets more than 2-3k byte.  I'm currently
working on several projects:  one with 512 words of code space and 128
bytes of ram; one with 16k word of code space and 1500 bytes of ram;
and one with 1/2Mb of code space and 1/8Mb of ram.  This isn't an
unusual mix or me.

For the most part, my applications are sensitive to cost, power, board
space, radiated EMF, and so on.  In part, that means in some cases
that an additional $20 in the CPU section makes the difference between
having a product which succeeds and having a product no one buys, even
if everything else is just fine.

Now for the smaller CPU environments, I usually use assembly, because
those applications often have extremely tight requirements.  I may
need to count cycles to make certain that either path across a branch
boundary takes the same cycle count, for example.  Further, the
application design is the big part of it and the coding time is rather
small by comparison.  So the issue of "faster coding" doesn't really
come into place as much on these smaller systems.  For the larger
applications, I often use C, mixed with assembly.

I can't afford templates, if instantiating support for a data type
causes functions I don't actually use to be generated and linked, for
example.  I can't afford exception handling, if the compiler still
generates defensive code even when I don't use any syntax in my code
for them.

For the greater part, well-optimized and well-designed libraries buy
me exactly zilch for my applications.  That's not entirely true, of
course.  Floating point libraries, for example, can be quite useful.
But by and large, libraries either aren't re-entrant; they make
assumptions which aren't true in my environment; they provide far too
many features and I have no choice but to include them all or use none
of them; and so on.  So talking about the benefits of C++ libraries,
templated or otherwise, makes little headway with me.  At least,
that's how it has been so far for me.

I don't have a purchased operating system, I write my own.  I don't
have a supplied library, I write my own.  I do care about ram usage,
stack usage, and program space.  I care a great deal about partial
template specialization in C++, but I wouldn't care much about access
to large, standard template libraries.

I care a great deal about having control over the processor I work on.
I care most of all in knowing exactly what kind of code is generated
by the compiler I use for syntax I write.  I need to have an intuitive
understanding of what happens for each and every line of source code I
lay down, when I'm writing it.

How many people using C++ know exactly how the vtable mechanism works?
In the face of multiple inheritance?  With virtual base objects?  How
many people how a C++ compiler supports dynamic casts or know what
causes the C++ compiler to generate (or not generate) support for it?
What mechanism does a C++ compiler use for exception handling?  What
does it cost?  Where?  If one stays away from a mechanism, how much of
it is still present?

I need to know what is generated, time and again.  In short, my focus
is exactly on the compiler itself and my ability to know what it does.
For folks working on large systems, it's enough for them to know that
it "doesn't cost much."  For me, cost isn't just a little bit of code
space, a little bit of ram space, and a little bit of execution time.
Sometimes, it's not a matter of degree, but a matter of YES/NO,
GOOD/BAD, WORKS/DOESN'T WORK.  I can't leave these details as some
abstract matter of implementation I can ignore.  Often, the compiler
makes decisions about "what's works for non-critical situations"
because that is where many of the applications are at.

But that's not where MY applications are at.  All the details must be
well understood.  The compiler itself and the linker support is my
main focus.  Not the libraries.

Hopefully, that gives an idea of where I'm coming from to those who
use C++ as part of their application development on systems where the
equivalent transistor count is measured in the 100's of millions or
billions.  I just don't live in their world.

So I'm speaking as one who uses assembly and C for their current
embedded applications and who would enjoy using a subset of C++.  But
I also have some concerns, too.

C++ as a Superset of C
----------------------

Strictly speaking, C++ is not a superset of C.  If unsure of that
fact, pages 816 to 818 in Stroustrup's 3rd edition of "The C++
Programming Language" indicates that some ANSI C programs are not
valid C++ and includes examples, as well.  But for many practical
purposes, developing new source code for C++ looks about like working
with a superset of C.

But it is the object code generation that is more the question mark
for an embedded programmer.  Not so much the source code input to the
compiler.

C++ Exception Semantics
-----------------------

For embedded use, this is an area which worries me where separate
compilation is supported (which it is, in every case I am aware of.)

I know.  Most folks just say, "Well, don't use exceptions then."  But
a properly functioning C++ compiler, it seems to me, must generate
correct code for source code unit A when it has absolutely no idea
what kind of exception handling may be required in source code unit B,
compiled separately and perhaps at a very different time.  And I have
absolutely no confidence at all that the linkers available to an
embedded programmer will cover over the problem I'm about to
illustrate here.

Take this sequence of code, found as part of some function in some
source code file:
       .
       .
       foo ();
       String s;
       foo ();
       .
       .

For purposes of discussion, assume this fragment occurs as part of a
routine that doesn't use try..catch at all in a source code module
that doesn't use try...catch or declare any throws, either.  In fact,
assume the module was written almost like C code by someone who wasn't
thinking about or worrying over exceptions at all.  It might even be a
C source code file modified slightly to take advantage of a few C++
features, such as the String class.

Also, for purposes here, assume that foo() is an external procedure
and that the compiler has a declaration for it, but does not know its
definition.

The C++ compiler, being a smart and proper C++ compiler, sees the
first call to foo() and can just allow a normal stack unwind to occur
if foo() throws an exception.  In other words, no extra code is needed
at this point to support the unwind process.  But once String s has
been created, the C++ compiler knows that it must be properly
destroyed before an unwind can be allowed if an exception occurs later
on.  So the second call to foo() is semantically different from the
first.  If the 2nd call to foo() throws an exception (which it may or
may not) in foo(), the compiler must have placed code designed to
handle the destruction of String s before letting the usual unwind
occur.

Now, the above is a case where a common, garden variety embedded
programmer would imagine that the two calls to foo() would take the
same time, require the same resources, and otherwise be the same.
Most programmers I know would believe and defend that position, even
when told that instead of a C compiler it is a C++ compiler looking at
the source code.  Even the more sensitive thinking programmers who are
aware of exception handling, stack unwinding, and so on, would tend to
pause for a while when faced with a source file which quite simply
contains NO try..catch blocks, no throws, and otherwise completely
avoids any use of C++ syntax related to exceptions.

Yet the C++ compiler *must* be aware of the difficulties and *must*
generate different code in these cases, where foo() is permitted to
generate exceptions.  And without an empty throw clause in it's
declaration, the C++ compiler must assume that it may.

All this, in a snip of code in a function in a module none of which
has any syntax dealing with exceptions at all.

Now, I know it is possible to declare foo() with a throw in the
declaration so that the compiler knows it cannot throw an exception.
The compiler may be able to do better, in code generation in such a
case where careful, explicit attention has been given to the function
declarations.  But in reality, in embedded systems trying to make th
transition to using C++ with programmers learning to use C++ features
and perhaps modifying existing code to be compiled with a C++
compiler, this is ...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Ok Enough Which is faster C or C++" by Ioannis Vranos
Ioannis Vranos  
View profile  
 More options Mar 18 2002, 7:51 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: "Ioannis Vranos" <noi...@no.spam.yahoo.com>
Date: Mon, 18 Mar 2002 14:51:14 +0200
Local: Mon, Mar 18 2002 7:51 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Eric Doenges" <Eric.Doen...@lpr.ei.tum.de> wrote in message

news:doenges.1016437690@lpr.e-technik.tu-muenchen.de...

You are right. The code:

#include <iostream>
#include <cstdio>
#include <ctime>
#include <climits>

int main()
{
 using namespace std;

 clock_t t1, t2, t3, t4;
 unsigned long i;
 const unsigned long LIMIT=16384;

 for(t2=clock(); !((t1=clock())-t2); )
   ;
 for(i=0; i<LIMIT; i++)
    printf("This is useless test, \"Pinky we will take over the
world...\"\n\"Naarf!\"\n");

 t2=clock();

 for(t4=clock(); !((t3=clock())-t4); )
   ;
 for(i=0; i<LIMIT; i++)
    cout<<"This is useless test, \"Pinky we will take over the
world...\"\n\"Naarf!\"\n";

 t4=clock();

 printf("\nprintf() operations took %lu clock_t\n",
static_cast<clock_t>(t2-t1));
 cout<<"cout operations took " << t4-t3<<" clock_t"<<endl;

}

produces in my machine (MINGW32 compiler). I have run them minimized
because printing these on screen on the fly would take considerable
time.

1st run:

printf() operations took 4686 clock_t
cout operations took 982 clock_t

2nd run:

printf() operations took 4957 clock_t
cout operations took 971 clock_t

Does this mean "C is slower"? Of course not. But it can't be faster than
C++.

Also check http://users.forthnet.gr/ath/jvr/c++faq.htm for another
timining experiment i have done.

--
Ioannis

* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ioannis Vranos  
View profile  
 More options Mar 18 2002, 7:59 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.programming, comp.arch.embedded
From: "Ioannis Vranos" <noi...@no.spam.yahoo.com>
Date: Mon, 18 Mar 2002 14:58:59 +0200
Local: Mon, Mar 18 2002 7:58 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
"Richard Heathfield" <bin...@eton.powernet.co.uk> wrote in message

news:3C95AFBD.FBC7D218@eton.powernet.co.uk...

> Ioannis Vranos claimed that MSVC++ was the most broken C++ compiler
out
> there (or some similar words). I showed him that this is not true, by
> providing an example of an even more broken C++ compiler - one that is
> so broken it can't even compile a single C++ program. The
bootstrapping
> joke was just that - a joke.

Well, next time don't chalenge if VC++ is not the most broken compiler.
You are going against common sense. :P Seriously speaking i said that as
an exaggeration, just don't comment on ANSI C++ code that it doesn't
compile under VC++. :)

--
Ioannis

* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Pop  
View profile  
 More options Mar 18 2002, 10:42 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.arch.embedded
From: Dan....@ifh.de (Dan Pop)
Date: 18 Mar 2002 15:37:05 GMT
Local: Mon, Mar 18 2002 10:37 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
In <NBnk8.17405$P4.1496...@newsread2.prod.itd.earthlink.net> "Steve Wheeler" <swheeler...@earthlink.net> writes:

This was the purpose of the limit and the reason it was unavoidable.
The only question left open was the actual value of the limit.  IBM chose
a limit that was 10 times higher than the maximum memory capacity of the
computer's system board.  Doesn't look unreasonable to me.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan....@ifh.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Pop  
View profile  
 More options Mar 18 2002, 11:12 am
Newsgroups: comp.lang.c, comp.lang.c++, comp.arch.embedded
From: Dan....@ifh.de (Dan Pop)
Date: 18 Mar 2002 15:55:26 GMT
Local: Mon, Mar 18 2002 10:55 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
In <OInk8.1$JX3.4...@typhoon.southeast.rr.com> "Keith Brafford" <kbraff...@nc.rr.com> writes:

>"Steve Wheeler" <swheeler...@earthlink.net> wrote in message news:NBnk8.17405$P4.1496522@newsread2.prod.itd.earthlink.net...
>> Wasn't the 640k limit so that they could put video RAM and ROM space for
>> peripheral boards into the 1MB that the 8088 could address?

>No.  640K was the limit because Bill Gates said that was all
>we'd ever need *jk* :-)

>I've always felt that 640K was a reasonable limit based on the
>cascaded effect of 3 different companies' work on the PC.

>Microsoft gave us that limit because IBM put a whole bunch of
>memory-mapped hardware (video, BIOS stuff, etc.) up high
>in 1MB that the PC could address.

Microsoft gave you no limit: the limit was already there, in the hardware.

>IBM put that stuff there because they chose the Intel 8088,
>which had its reset vector at the high end of things and needed
>the bottom part of memory for the interrupt vector table.

Well, having the reset vector at the end of the address space was a good
design decision.  I've seen 8-bit systems having it at address 0 jumping
through hoops so that they could have their ROMs at the end of the
processor's address space.  CP/M-80 anyone?

Regardless of this issue, the limit had to be there, some place, because
the 1 MB of the processor address space had to be divided between system
RAM and BIOS (system & peripheral extensions) + extension cards RAM
(frame buffers, disk buffers, network card buffers, expanded memory cards
address space).

>So I blame Intel :-)

The blame should go to IBM for choosing a 16-bit processor with a
horrible ISA and an 8-bit external interface.  I don't know if the 68000
was shipping in quantity at the time the decision was made, but it should
have been the obvious choice.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan....@ifh.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blane Bramble  
View profile  
 More options Mar 18 2002, 11:39 am
Newsgroups: comp.arch.embedded
From: "Blane Bramble" <bl...@spamguard.lyzard.net>
Date: Mon, 18 Mar 2002 16:37:58 -0000
Local: Mon, Mar 18 2002 11:37 am
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Dan Pop" <Dan....@ifh.de> wrote in message

news:a752le$are$1@sunnews.cern.ch...

> In <OInk8.1$JX3.4...@typhoon.southeast.rr.com> "Keith Brafford"
<kbraff...@nc.rr.com> writes:

> The blame should go to IBM for choosing a 16-bit processor with a
> horrible ISA and an 8-bit external interface.  I don't know if the 68000
> was shipping in quantity at the time the decision was made, but it should
> have been the obvious choice.

I did see an article a while back that claimed the choice of the 8088 was
made because it would interface relatively easily to the existing 8080/8085
support chips, whereas the 68000 although a superior design either didn't
have necessary support chips available, or the cost of interfacing to them
was considered too expensive.

Blane.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Brafford  
View profile  
 More options Mar 18 2002, 3:09 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.arch.embedded
From: "Keith Brafford" <kbraff...@nc.rr.com>
Date: Mon, 18 Mar 2002 20:08:50 GMT
Local: Mon, Mar 18 2002 3:08 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++

"Dan Pop" <Dan....@ifh.de> wrote in message news:a751j1$7up$1@sunnews.cern.ch...
> This was the purpose of the limit and the reason it was unavoidable.
> The only question left open was the actual value of the limit.  IBM chose
> a limit that was 10 times higher than the maximum memory capacity of the
> computer's system board.  Doesn't look unreasonable to me.

Sure 10x memory is an order of magnitude; sounds reasonable...until
you realize that 10x is only about 4.75 years worth of memory growth
according to Moore's Law!

--Keith Brafford


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dann Corbit  
View profile  
 More options Mar 18 2002, 3:51 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.arch.embedded
From: "Dann Corbit" <dcor...@connx.com>
Date: Mon, 18 Mar 2002 12:35:37 -0800
Local: Mon, Mar 18 2002 3:35 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
"Keith Brafford" <kbraff...@nc.rr.com> wrote in message

news:mPrl8.71$wf.176604@typhoon.southeast.rr.com...
> "Dan Pop" <Dan....@ifh.de> wrote in message

news:a751j1$7up$1@sunnews.cern.ch...

> > This was the purpose of the limit and the reason it was unavoidable.
> > The only question left open was the actual value of the limit.  IBM
chose
> > a limit that was 10 times higher than the maximum memory capacity of the
> > computer's system board.  Doesn't look unreasonable to me.

> Sure 10x memory is an order of magnitude; sounds reasonable...until
> you realize that 10x is only about 4.75 years worth of memory growth
> according to Moore's Law!

At which time the system will be completely depreciated and you will buy a
new one.
;-)
--
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jos A. Horsmeier  
View profile  
 More options Mar 18 2002, 5:36 pm
Newsgroups: comp.lang.c, comp.lang.c++, comp.arch.embedded
From: "Jos A. Horsmeier" <j.a.horsme...@wanadoo.nl>
Date: Mon, 18 Mar 2002 23:39:13 +0100
Local: Mon, Mar 18 2002 5:39 pm
Subject: Re: [OT] Re: Ok Enough Which is faster C or C++
"Dan Pop" <Dan....@ifh.de> wrote in message

news:a752le$are$1@sunnews.cern.ch...

> In <OInk8.1$JX3.4...@typhoon.southeast.rr.com> "Keith Brafford"
<kbraff...@nc.rr.com> writes:
> >So I blame Intel :-)
> The blame should go to IBM for choosing a 16-bit processor with a
> horrible ISA and an 8-bit external interface.  I don't know if the 68000
> was shipping in quantity at the time the decision was made, but it should
> have been the obvious choice.

Well, in those days the 68000 were shipped by the dozen in the Netherlands.
I remember a TNO box running (those were the days) a unix version 6 os
on a single 68K and some mysterious backup 68K running one step behind
(and I mean one _clock_ step behind) just because it wasn't possible
to get a decent MMU cooperating with the 68K in those days ...

IIRC no MMU could solve those problems because something really bad
happened inside that 68K when a page fault was detected. I (luckily)
forgot the details though ...

kind regards,

Jos aka j...@gen.nl

ps In those days a simple 2MHz 6502 could outrun a 4.71MHz 8086 by
   more than a factor of pi ;-)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 126 - 150 of 228 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google