logoalt Hacker News

myrmidontoday at 1:03 PM3 repliesview on HN

> 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.


Replies

kryptiskttoday at 2:59 PM

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

No, you can't, C is lacking a lot that C++ brings to the table. C++ has abstraction capabilities with generic programming and, dare I say it, OO that C has no substitute for. C++ has compile-time computation facilities that C has no substitute for.

jonathrgtoday at 1:11 PM

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.

g947otoday at 1:07 PM

Mind if I ask whether you speak of that from a professional embedded system engineer's perspective?

show 1 reply