Practical Guide to Bare Metal C++
33 points
3 days ago
| 6 comments
| arobenko.github.io
| HN
myrmidon
11 minutes ago
[-]
> There are multiple articles of how C++ is superior to C, that everything you can do in C you can do in C++ with a lot of extras, and that it should be used even with bare metal development

An interesting perspective. Could turn it around as "everything you can do in C++ you can do in C with a lot less language complexity".

My personal experience with low-level embedded code is that C++ is rarely all that helpful, tends to bait you into abstractions that don't really help, brings additional linker/compiler/toolchain complexity and often needs significant extra work because you can't really leverage it without building C++ abstractions over provided C-apis/register definitions.

Would not generally recommend.

reply
jonathrg
4 minutes ago
[-]
You definitely need discipline to use C++ in embedded. There are exactly 2 features that come to mind, which makes it worth it for me: 1) replacing complex macros or duplicated code with simple templates, and 2) RAII for critical sections or other kinds of locks.
reply
g947o
8 minutes ago
[-]
Mind if I ask whether you speak of that from a professional embedded system engineer's perspective?
reply
pjmlp
1 hour ago
[-]
While tag dispatching used to be a widely used idiom in C++ development, it was a workaround for which nowadays there are much better alternatives with constexpr, and concepts.
reply
tialaramex
13 minutes ago
[-]
Surely one of the obvious reasons you'd want tagged dispatch in C++ isn't obviated by either of those features? Or am I missing something?

Suppose Doodads can be constructed from a Foozle either with the Foozle Resigned or with the Foozle Submitted. Using tagged dispatch we make Resigned and Submitted types and the Doodad has two specialised constructors for the two types even though substantively we pass only the Foozle in both cases.

In a language like Rust all the constructors have names, it's obvious what Vec::with_capacity does while you will still see C++ programmers who thought constructing a std::vector with a single integer parameter does the same because it's just a constructor and you'd need to memorize what happens.

reply
saltmate
19 minutes ago
[-]
This seems very well written, but has a lot of requirements/previous knowledge required by a reader. Are there similar resources that fill these gaps?
reply
menaerus
21 minutes ago
[-]
Outdated, opinionated, platform-specific, and incorrect.
reply
VorpalWay
38 minutes ago
[-]
Why does the link go to the abstract classes heading, halfway down the page?
reply
m00dy
8 minutes ago
[-]
just use Rust, and never look back.
reply