Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17669

Re: [OT] Quick intro to C++ for a Python and C user?

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: [OT] Quick intro to C++ for a Python and C user?
Date 2011-12-21 15:37 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <jcsueu$cmg$1@reader1.panix.com> (permalink)
References <jcqha6$mug$1@reader1.panix.com> <9lc2u5FilrU1@mid.individual.net> <jcqrtk$4g4$1@reader1.panix.com> <7xr4zzx8k9.fsf@ruckus.brouhaha.com> <9le7c5F1lsU1@mid.individual.net>

Show all headers | View raw


On 2011-12-21, Neil Cerutti <neilc@norwich.edu> wrote:
> On 2011-12-20, Paul Rubin <no.email@nospam.invalid> wrote:
>> Grant Edwards <invalid@invalid.invalid> writes:
>>> Oops. I should have mentioned this is for embedded systems
>>> programming so templates in general (and STL in particular)
>>> are probably off the table.
>>
>> Templates are how C++ does generics and I'd expect them to
>> appear in be used in embedded programming as well as elsewhere.

I've only worked on the perphery of a couple embedded projects that
used C++, but it seems to be farily common practice to prohibit the
use of templates in embedded code.  The problem seems to be that
people writing C++ code don't really understand the language, how
templates work, or (in general) the implications of the code they
write.  So, you have to prohibit anything that can be easily misused
or cause non-obvious problems.

For exaple (quoting from http://en.wikipedia.org/wiki/Embedded_C%2B%2B):

  Embedded C++ is a proper subset of C++. The following language
  features have been removed:

    Multiple inheritance
    Virtual base classes
    Run-time type information (typeid)
    New style casts (static_cast, dynamic_cast, reinterpret_cast and const_cast)
    The mutable type qualifier
    Namespaces
    Exceptions
    Templates

Some people go further and prohibit any run-time object creation.
    
>> They can bloat up the code if you're not careful

Bingo.  In my experience, many (if not most) C++ programmers don't
understand enough of the language to realize what "being careful"
means.

>> (if function f has several parameters, you can end up with a
>> separate, specialized copy of f for every combination of types that f
>> is called with in the program), but in the typical monomorphic
>> situation they don't add any overhead.  I'm not sure about the
>> situation with STL.  Anyway, templates aren't terribly hard to
>> understand.
>
> Moreover, if you don't plan to take advantage of templates or
> inheritance, then you could as well write C++ compatible C and be
> pretty happy with the results.

Well, there are other C++ features that C doesn't have (e.g.
exceptions -- but they're often prohibitted in embedded programming as
well).

Personally, I think C++ is an awful language in general and a _really_
awful language for embedded systems work.

-- 
Grant Edwards               grant.b.edwards        Yow! PEGGY FLEMMING is
                                  at               stealing BASKET BALLS to
                              gmail.com            feed the babies in VERMONT.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[OT] Quick intro to C++ for a Python and C user? Grant Edwards <invalid@invalid.invalid> - 2011-12-20 17:40 +0000
  Re: [OT] Quick intro to C++ for a Python and C user? Neil Cerutti <neilc@norwich.edu> - 2011-12-20 18:36 +0000
    Re: [OT] Quick intro to C++ for a Python and C user? Grant Edwards <invalid@invalid.invalid> - 2011-12-20 20:41 +0000
      Re: [OT] Quick intro to C++ for a Python and C user? Paul Rubin <no.email@nospam.invalid> - 2011-12-20 13:00 -0800
        Re: [OT] Quick intro to C++ for a Python and C user? Neil Cerutti <neilc@norwich.edu> - 2011-12-21 14:04 +0000
          Re: [OT] Quick intro to C++ for a Python and C user? Roy Smith <roy@panix.com> - 2011-12-21 09:26 -0500
          Re: [OT] Quick intro to C++ for a Python and C user? Grant Edwards <invalid@invalid.invalid> - 2011-12-21 15:37 +0000
            Re: [OT] Quick intro to C++ for a Python and C user? Neil Cerutti <neilc@norwich.edu> - 2011-12-21 16:16 +0000
              Re: [OT] Quick intro to C++ for a Python and C user? Grant Edwards <invalid@invalid.invalid> - 2011-12-21 21:02 +0000
                Re: [OT] Quick intro to C++ for a Python and C user? Ethan Furman <ethan@stoneleaf.us> - 2011-12-21 13:15 -0800
                Re: [OT] Quick intro to C++ for a Python and C user? Roy Smith <roy@panix.com> - 2011-12-21 20:02 -0500
                Re: [OT] Quick intro to C++ for a Python and C user? Neil Cerutti <neilc@norwich.edu> - 2011-12-22 13:19 +0000
  Re: [OT] Quick intro to C++ for a Python and C user? Paul Rubin <no.email@nospam.invalid> - 2011-12-20 11:43 -0800
  Re: [OT] Quick intro to C++ for a Python and C user? Grant Edwards <invalid@invalid.invalid> - 2011-12-20 20:51 +0000
    Re: [OT] Quick intro to C++ for a Python and C user? Paul Rubin <no.email@nospam.invalid> - 2011-12-20 13:06 -0800

csiph-web