On 2011-12-21, Neil Cerutti <ne...@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. -- http://mail.python.org/mailman/listinfo/python-list