By "modern C++", I meant "C++11" or above, rather than C++98/C++03.
There are a fair number of features introduced in C++11, and enhanced in
C++14 (and C++17), that greatly improve the language (in my humble and
not too experienced opinion).
> I've been on Linux for too long (a decade) but it seems to me the
> market for non-Unix embedded environments is shrinking, and that gcc
> (including the C++ compiler) is replacing proprietary C compilers
> inside that market, too.
gcc (and occasionally clang) is certainly taking more of the embedded C
and C++ space. In particular, it dominates the ARM development market,
and is also very popular for AVR and msp430, and for new architecture,
gcc and/or clang is almost always the starting point for the tools. But
there are lots of parts of the embedded world where gcc is rarely seen.
In safety-critical or automotive industries, companies are extremely
conservative - suppliers like Green Hills or IAR dominate even when gcc
gives a better compiler. In legal terms, if something goes wrong, "I
paid lots of money for an "industry standard" certified development
tool" is a better defence than "I picked the tool with fewest bugs".
And for smaller cpus, like the infamous 8051, there are no gcc ports.
One of the reasons for this is that C++ is getting increasingly
difficult to parse and implement. Proprietary vendors simply cannot
keep up with the development costs, and do not try.
And for targets which are not dominated by gcc, C++ support is generally
limited and expensive. It seldom goes beyond C++03 standards, and C++
support can cost many times the price of a C compiler. (For example,
Metrowerks for Freescale's chips is free for most targets up to a quite
usable code size limit, as long as you stick to C - write a single line
of C++, and you need $5K for a permanent license.)
Much of the embedded industry can be incredibly backwards regarding
language support. Two or three years ago I saw an advert for the latest
version of a DSP development suite, costing multiple $K - "now
supporting most of C99" (no C++ of any sort). MISRA-C, the coding
standard required for automotive development in the EU, upgraded to C99
support in 2012. At our company we have newly-purchased development
tools (for conformance testing of a communications stack) that can only
be run on DOS - without any virtualisation.
And while in the *nix world it is not uncommon to find C code whose
heritage goes back 20 years, in the embedded world the same code needs
to be compiled on the 20 year old tools for the 20 year old
architecture. (I think modification of 19 year old code is my personal
record.)
For this sort of thing, language stability in C is clearly an advantage.
Arguably, picking the current best supported C++ version and sticking
with that for the next 20 years is a better choice - and in some cases,
that is true. But a new C programmer educated and trained in C11 would
have little problem understanding and working with C90 code, while a new
C++ programmer trained only in C++14 would find C++98 code a different
language. There are pros and cons here.
For other types of embedded development, the power and flexibility of
modern C++ is essential - at the other end of the scale from these
long-term systems, there are embedded products that get 3 months of
development, three months of sales, and then they are obsolete.
>
>> - and anyone working with the
>> code has to have learned the new features. But if I write good, clear,
>> modern C code, it will compile on anything, and any C programmer can
>> work with it.
>
> You're right: /that/ last thing is a reason C isn't unnecessary.
> There are plenty of good C programmers around, and you sometimes want
> to cooperate with them. No, scratch that: you /frequently/ want to
> cooperate with them.
(Of course, there are plenty of /bad/ C programmers around too!)
>
> At the same time, with those programmers, I cannot help sometimes
> thinking "wow, she would get even more stuff done if she spent some
> time learning C++!". C++ is, to me, a logical next step. If you're
> good with C, you'll be even better with C++, and nothing you've
> learned so far is wasted.
I am not sure that is true. C is a far simpler language than C++ - for
the same amount of time and effort, you can be an expert C programmer or
a mediocre C++ programmer. Which is best for the job? The skills
needed for good C programming and good C++ programming are highly
related, but not identical.
And while a good C++ program has many advantages over a good C program,
a /bad/ C program is, I think, easier to understand and fix than a /bad/
C++ program.
>
>> C++ has been getting many more features over time - and that is an
>> advantage for C++. You can write neater, clearer, faster, and safer
>> code with C++11 than with C++03, and C++14 and C++17 continue to improve
>> the language.
>>
>> So while I see that there is steadily more scope for the use of C++ in
>> traditional C domains (such as in an increasing proportion of embedded
>> development), C is far from "crippled" or "unnecessary".
>
> I retract my statement about "unnecessary", but I still maintain the
> "crippled" part. It's not derogatory. It's just how I see my own C
> programming: I know how I would have written the code in C++, but I
> have to translate it to less expressive C code.
"Crippled" implies that the language has changed from being a fully
working and useful language into something more limited and sub-optimal.
The rise of an alternative language, C++, that is often a better choice
than C does not mean that C is crippled. It merely means that C has
stayed still while C++ has moved on.
>
> C can, objectively, be seen as more or less a small subset of C++, and
> C++ is readily available for free to almost everybody. In that sense C
> is crippled.
No. EC++ was crippled, because they started with C++ and took out many
useful parts for no good reason. C is not crippled, because it is the
same as it always has been.
>
> Of course I have to make my C code more or less idiomatic C -- if I
> tried to emulate C++ in C I would be as rude as the C programmers
> writing C++ code as if it was C -- but I cannot ignore the lessons C++
> taught me, about the merits of type safety and so on.
There is no single "correct" way to write C or C++ - and IMHO
well-written code in any language uses the language, the compiler and
other tools as "safely" as possible.