
What can C++ do for embedded systems developers? [video] - matt_d
https://www.youtube.com/watch?v=VoHOLDdfDhk
======
sbradford26
It is very interesting because directly states that for C++ to be as efficient
you need to have the optimizer on. Now for most scenarios that makes perfect
sense but for aerospace we need to be able to match the code directly between
the assembly and C code. Without this it is incredibly difficult to do full
verification.

~~~
fooker
>Without this it is incredibly difficult to do full verification.

You can verify the optimizations on their own. Example:
[https://www.cs.utah.edu/~regehr/papers/pldi15.pdf](https://www.cs.utah.edu/~regehr/papers/pldi15.pdf)

~~~
gmueckl
In the framework of safety-critical software correctness of the compiler is a
prerequisite, but not seen as sufficient to prove the correctness of the
actual translation.

~~~
fooker
Why?

~~~
gmueckl
Because the compiler is only correct if its execution environment is also
correct. This cannot be guaranteed.

And also because the relevant standards say so.

~~~
fooker
Can you point me to these standards? I do research in this field and it would
be helpful to refer to such standards in papers.

~~~
gmueckl
For traceability you would need to look at Do-178C. I am currently not aware
that ISO 61508 (general functional safety) and ISO 26262 (automotive
functional safety) require traceability between source code and executable
machine code.

All standards specify different levels of safety. Lower levels come with fewer
requirements and are easier to implement, but are recognized as less reliable
and therefore limited to less critical applications.

------
nrclark
Around the 30 minute-mark, I noticed some weird syntax that I've never seen
before. I dabble in C++ at my job, so I'm not a total newbie. But what do
those braces mean on 'weekday'? Is that some kind of class constructor or
something?

Code in question was:

    
    
      cout << weekday{October/19/2017} << '\n';

~~~
Game_Ender
It's "aggregate initialization" [0]

    
    
      struct S {
          int x;
          struct Foo {
              int i;
              int j;
              int a[3];
          } b;
      };
      S s1 = { 1, { 2, 3, {4, 5, 6} } };
    

0 -
[https://en.cppreference.com/w/cpp/language/aggregate_initial...](https://en.cppreference.com/w/cpp/language/aggregate_initialization)

~~~
planteen
I don't think that is what is going on, this is invoking the constructor for
the weekday class with the "modern" uniform initilization syntax. This solves
the old C++ most vexing parse problem.

[https://en.wikipedia.org/wiki/Most_vexing_parse](https://en.wikipedia.org/wiki/Most_vexing_parse)

It seems like this is the C++ class in question:
[https://howardhinnant.github.io/date/iso_week.html](https://howardhinnant.github.io/date/iso_week.html)

------
jstewartmobile
When many of these low power chips have less than 64K of RAM, C++ is a
terrible mistake. Once the program reaches even a modest level of complexity,
expect blown stacks left and right.

I have had to clean-up so many of these things! And the guy who insisted on
using C++ in the first place is always like, "I'll just change the compiler
flags, and then it'll be OK." And that never fixes it.

~~~
wdfx
I'm currently writing a hobby project in c++ for esp8266. I'm using about 35%
DATA and 40% PROGRAM according to the compiler... seems to be ok so far
(though my application does not need to allocate arbitrary memory right now,
almost all is determined by initialisation).

On the other hand I'm trying to export some data at work from a web app...
Firefox grows to 8.9GB ram usage then reports "uncaught exception: out of
memory" :(

~~~
octorian
I used C for my last ESP8266 project, which seemed mostly okay. It did involve
a fair amount of HTTP request/response and parsing, where I was just careful
to do things incrementally. I don't think I ever considered C++ for the
project. (The most annoying thing was probably the large number of callbacks I
had to track state across for anything involving a TCP socket.)

For my current project, I moved onto the ESP32, where I'm also sticking with
C. On this project, there's a lot less network code. Now the annoying part is
the lack of built-in data structures in C. I'm making up for it with the
uthash project, but I really wish it wasn't something where every project had
to "roll their own" (or pull in some macro library, none of which seem to be
"the standard everyone uses")

C++ would definitely make the code look a lot prettier, even if only for the
sake of organization. I still just hesitate, because I'd then be tempted to
wrap all the C framework APIs in C++ classes which would only add to the
bloat.

