C++ in embedded systems - Page 6

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: C++ in embedded systems

Quoted text here. Click to load it

I never said C++'s lack of OO purity prevents using it effectively - I
said that it was obvious that C++ was not designed to *be* OO, but
rather to *add* OO to a procedural base language.


Quoted text here. Click to load it

Absolutely.  The very issue Andras Tantos and I were discussing
previously: parametric dispatch on object parameters.  

Anytime you have a base class pointer (or reference) and must pass the
object to a function based on the runtime type, you have to do it
manually.  Code such as the following (abbreviated) cannot select the
right overload of F() based on the runtime type of the object and the
call to G() won't compile.

    :
class A;
class B : public A;
void F( A &a );
void F( B &b);
void G( B &b );
    :
A *pA = new B;
F( *pA );     // calls F(A) not F(B)
G( *pA );     // error ... argument is not a reference to B
    :

Whenever you need code such as this, you must test for the actual
runtime type, construct a new pointer or reference with the
appropriate static type and manually dispatch the call - in effect
manually doing everything objects are supposed to do automatically.

I'm sure if I looked back at C++ code I've written over the years I
can find other really annoying examples.  The parametric dispatch
issue just happened to be at hand.


George

Re: C++ in embedded systems
Quoted text here. Click to load it

This is one of those misconceptions I was talking about.  This is not
OOP at all.  This is just function overloading.  Which has nothing to
do with OOP.  What you really want to do is use polymorphism.

--jc
--
Jimen Ching (WH6BRR)       snipped-for-privacy@flex.com     snipped-for-privacy@uhm.ampr.org

Re: C++ in embedded systems

Quoted text here. Click to load it

You're missing the point ...

It is not a misconception about OO at all ... it is a case where
objects in C++ don't behave as objects, but instead behave as raw
data, forcing the programmer to explicitly code the desired object
polymorphic behavior.

I know the difference between object polymorphism and parametric
polymorphism.  My point is that C++ purports to provide both and
manages to accomplish neither when the two concepts are used
simultaneously.

George

Re: C++ in embedded systems
Quoted text here. Click to load it

Do you have a source where it states that function overloading is
supposed to provide polymorphic behavior?

Quoted text here. Click to load it

Object polymorphism implies inheretance and member functions, but your
example contain neither.  Parametric polymorphism implies templates,
but your example doesn't use this either.  Your assertions would be a
lot more powerful, if they were backed up with concrete examples that
actually contain the semantics you're discussing.

--jc
--
Jimen Ching (WH6BRR)       snipped-for-privacy@flex.com     snipped-for-privacy@uhm.ampr.org

Re: C++ in embedded systems

Quoted text here. Click to load it


Polymorphism is the quality of being able to assume different forms.

Do you know of a reason to allow differently parametered functions to
have the same name apart from wanting the name to mean different
things?




Quoted text here. Click to load it

I'm unclear as to whether you mean "template" mathematically as a
generic specification of function or whether you mean a C++ template.
I'm going to assume the mathematical usage as the other makes very
little sense in this discussion.


WRT programming models, object polymorphism is just a restrictive,
special case of parametric polymorphism obfuscated by syntactic sugar.
I'm not going to debate the merits of reasoning with the "special"
object model vs. the general functional one - we can continue that
discussion in comp.lang.whatever ... it's several parsecs further OT
than we already are now.
 

ISO/IEC 14882 sections 3 [basics] and 10 [classes] state that name
lookup may associate more than one declaration with a name if the name
is found to be a function, and the set of declarations forms a set of
overloaded functions.  Section 13 [overloading] spells out the
resolution of overloaded functions.  A function containing an implicit
object parameter, ie. a member function, is determined statically at
compile time from the (positional) static types of the function
parameters excluding the implicit object parameter.  The actual
function is determined at run time by the actual type of the implicit
object parameter.

C++ implements a half baked scheme of statically resolved parametric
polymorphism which disallows most uses of object parameters and uses a
special case to allow one particular syntactic form to be handled at
run time while disallowing all other equivalent syntactic forms.

In simple terms: C++ implements object polymorphism as lobotimized
parametric polymorphism.


Quoted text here. Click to load it

You asked me in what situation(s) C++'s distinction between objects
and other data types mattered.  I answered that question and provided
a simple example.  The issue you missed entirely is this:

    "Objects in C++ don't always behave as objects."


George

Re: C++ in embedded systems
Quoted text here. Click to load it

I guess I wasn't clear in my response to this assertion.  So let me state
it explicitly.

    "No one cares!  Most people can still do OOP in C++ just fine."

--jc
--
Jimen Ching (WH6BRR)       snipped-for-privacy@flex.com     snipped-for-privacy@uhm.ampr.org

Re: C++ in embedded systems

Quoted text here. Click to load it

Well, your first statement is obviously false.  As to the second, I
defer to one wiser than myself, who once wrote: "It is clearly
possible to write good code in C++.  It's just that no one does."

Regards,

                               -=Dave
--
Change is inevitable, progress is not.

Re: C++ in embedded systems
Quoted text here. Click to load it

I guess I should have chosen better words.

Quoted text here. Click to load it

Yes, I totally agree.  Considering this sub-thread is based on misconceptions
of C++, this observation would be implied...

--jc
--
Jimen Ching (WH6BRR)       snipped-for-privacy@flex.com     snipped-for-privacy@uhm.ampr.org

Re: C++ in embedded systems

Quoted text here. Click to load it

To know that "no one does" needs omniscience, not mere wisdom. So your
source was not a particularly wise person, then! In fact, I've seen quite a
lot of "good" C++ code, though there's a lot more bad code about - in all
languages. C++ is certainly not foolproof; the answer is not to put it in
the hands of fools (or, at least not to accept the output of such people as
viable code).

Peter.



Re: C++ in embedded systems

snip of some very well written stuff about C++ misconceptions

Quoted text here. Click to load it

Forgive me but IIRC the original poster I believe posed that very
question, not in those words exactly, I think he said is OOD the best
approach for embedded systems.

Ian


Re: C++ in embedded systems
Quoted text here. Click to load it

Well, I'll admit that there was mention of OOD.  But the last few sentences
of that post asked for comments on using C++ in embedded systems.

In any case, even if the original author wanted comments about procedural
vs. OO, that wasn't my intent in my response.  I only wanted to clear up
the misconceptions.  I'm not really interested in the procedural vs. OO
debate.  Both are good, both have their place.  It's not whether we should
or shouldn't, but when.  And that's all I'll say about that...

--jc
--
Jimen Ching (WH6BRR)       snipped-for-privacy@flex.com     snipped-for-privacy@uhm.ampr.org

Re: C++ in embedded systems
Quoted text here. Click to load it

Agree 100%

Ian


Re: C++ in embedded systems
snipped-for-privacy@yahoo.com (Mad@Spammers) wrote in message

Thank you all for your answers and debate. I read every post (or tried
to - there where some very short posts in the midst of long quotes I
just ignored :-( .)

All of them were very enlightening, even those aparently
controversial.

Regards.

Elder.

Re: C++ in embedded systems
Quoted text here. Click to load it


I went to the site and couldn't find any such article.

Re: C++ in embedded systems
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

You will get a much more readable page by appending "?print=true"
to that URL

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline