Live data from Hacker News

Learn Effective C++ for Embedded Code

luckyresistor.me

11–20 of 21 posts

Re: Learn Effective C++ for Embedded Code

#11
post #6

I’m always under the impression that C++ has some issues when it comes to embedded and that only a subset can be used, that the stdlib and stl cannot be used. I still don’t really understand how c++ behaves with exception handling thrown in the mix, where all sort of weird gotchas seemingly come into play. I get templates, classes, and constexpr might be incredibly valuable though. If used within reason to avoid code…

Pretty much everyone agrees exceptions aren't worth it, but there are plenty of opinions about what the best alternative is (returning bools, error codes, aborting the program, etc.)

Classes are unambiguously good, but polymorphism (specifically vtables) are controversial. Templating is great, but folk love to complain about code size in abstract to sound smart.

Dynamic memory allocations in general are forbidden, but in practice it's occasionally easier to just support it in some very limited way, and then lock the API down very tightly.

Re: Learn Effective C++ for Embedded Code

#12
post #9

Rust on embedded seems a hell of a lot more viable for large, complicated projects. You can basically use the entire standard library (sans io and alloc, obviously).

Entire core library you mean? std is normally not supported on embedded targets AFAIK.

Re: Learn Effective C++ for Embedded Code

#13
post #9

Rust on embedded seems a hell of a lot more viable for large, complicated projects. You can basically use the entire standard library (sans io and alloc, obviously).

Embedded is very conservative. While Rust is looking promising, it will be a while before it is trusted like the embedded subset of C++ is (that is no exceptions and other parts that embedded often turns off). That time may or not find faults with Rust (including some faults that are today considered a good thing).

The movers and shakers in the embedded C++ world are looking at Rust though.

Re: Learn Effective C++ for Embedded Code

#14
post #4

I'm a big fan of quantum leaps (www.state-machine.com) for c++ embedded. I am not affiliated with them in any way, just had a great experience with it.

I have not used their libraries or tools, but Miro Samek's book is great. There's a C implementation covered in it also. It's a bit of a master class in embedded C programming with careful use of structs and function pointers for "object orientation".

He also has an awesome YouTube channel which goes from pretty much zero and explains many embedded topics.

Oh, and the book is free: https://www.state-machine.com/psicc2

Re: Learn Effective C++ for Embedded Code

#16
post #7
post #6

I’m always under the impression that C++ has some issues when it comes to embedded and that only a subset can be used, that the stdlib and stl cannot be used. I still don’t really understand how c++ behaves with exception handling thrown in the mix, where all sort of weird gotchas seemingly come into play. I get templates, classes, and constexpr might be incredibly valuable though. If used within reason to avoid code…

> I still don’t really understand how c++ behaves with exception handling thrown in the mix In my experience you normally disable exceptions when working on embedded code. No RTTI either. > What’s debugging like? What's with debugging? Not different to C at all. > How do people agree on what subset of the language and it’s plethora of features to use? You agree on the language standard to use, you don't pull dependen…

Seeing c, seeing the assembly and memory layout, debugging is pretty easy. More than once I’ve ran into C compiler bugs. I can imagine running into the same issue with C++ being pretty troublesome?

Re: Learn Effective C++ for Embedded Code

#17
post #13
post #9

Rust on embedded seems a hell of a lot more viable for large, complicated projects. You can basically use the entire standard library (sans io and alloc, obviously).

Embedded is very conservative. While Rust is looking promising, it will be a while before it is trusted like the embedded subset of C++ is (that is no exceptions and other parts that embedded often turns off). That time may or not find faults with Rust (including some faults that are today considered a good thing). The movers and shakers in the embedded C++ world are looking at Rust though.

Gonna need a citation on that one. I work in the embedded world for a billion+ dollar company and there is zero interest or adoption in Rust.

Re: Learn Effective C++ for Embedded Code

#18
post #16
post #7

Earlier quoted context omitted.

> I still don’t really understand how c++ behaves with exception handling thrown in the mix In my experience you normally disable exceptions when working on embedded code. No RTTI either. > What’s debugging like? What's with debugging? Not different to C at all. > How do people agree on what subset of the language and it’s plethora of features to use? You agree on the language standard to use, you don't pull dependen…

Seeing c, seeing the assembly and memory layout, debugging is pretty easy. More than once I’ve ran into C compiler bugs. I can imagine running into the same issue with C++ being pretty troublesome?

Oh. Frankly I've probably never seen a compiler bug in my life. I have to look at the assembly sometimes though when debugging faults of various kinds, and I don't find matching C++ to assembly significantly more complicated than C. There is just a bit of additional knowledge maybe on how vtables work and that's it. Exceptions are probably a pain too, but embedded code doesn't allow them as a rule.

Re: Learn Effective C++ for Embedded Code

#20
post #13

Earlier quoted context omitted.

Embedded is very conservative. While Rust is looking promising, it will be a while before it is trusted like the embedded subset of C++ is (that is no exceptions and other parts that embedded often turns off). That time may or not find faults with Rust (including some faults that are today considered a good thing). The movers and shakers in the embedded C++ world are looking at Rust though.

Gonna need a citation on that one. I work in the embedded world for a billion+ dollar company and there is zero interest or adoption in Rust.

It has got enough attention that SG14 (the C++ embedded working group) is asking questions and trying to figure out what to do about it. Most of the committee seems aware of it, some have looked into it more than others.

That doesn't mean everyone is looking at it. Like I said, embedded is conservative, so it will be a while before everyone looks.

Post reply on HN