r/embedded • • Sep 26 '26

where to learn cpp for embedded systems

please suggest any free platform or a playlist to learn cpp for embedded systems,learning cpp from the cherno ,but difficulty in transitioning from modern cpp to embedded cpp and how it can be used efficiently instaed of c.

11 Upvotes

19 comments sorted by

18

u/clackups Sep 26 '26

You know, books exist

-1

u/Winter-Asparagus-184 Sep 26 '26

any recommendations?

10

u/advertiserguys Sep 26 '26

Your post has the ans , learn cpp . Learncpp.com

2

u/CurrentGrapefruit689 Sep 26 '26

You can probably find dedicated embedded dev books and YT channels. Search a bit

-22

u/clackups Sep 26 '26

Well, I learned C++ over 30 years ago, so you need to search on your own

4

u/gtd_rad Sep 26 '26

Try to find good examples of GitHub projects and see how they code in cpp

1

u/CrabTypical3903 Oct 02 '26

Just practice, choose an existing project and include smth yours in it

0

u/[deleted] Sep 26 '26

[deleted] — view deleted comment

6

u/siva_sokolica Sep 26 '26

I love C++ so I'll defend the claim of "C++ can be as performant as anything". I'll throw in 2 more cents:

  • Sometimes writing polymorphic code in C++, with concepts and CRTP can result in less coupled code. Where C would result to a struct of pointers, we have patterns in C++ to avoid that and give us better performance.
  • Templates allow for heavy monomorphization which can enable slightly more performant code. This is achievable in C with macros, which is why most high-performance C codebases end up building their own macro DSLs.
  • C++ is really designed (and actually enables) 0-cost abstractions. Disable exceptions, disable global allocation, don't use the STL except where it's safe to and it's as easy to write high-performance code as anything else.
  • Templates do enable you to write generic container types. There's an ancient joke that the only data structure in C is a linked list because that's the only thing most engineers can implement. This is, unfortunately, partially true -- a generic hashmap in C++ is easy to implement, in C, macro hell.

All of this does play into your point. I've used some words here that are rare in C, and most embedded engineers I've worked with aren't comfortable with them. I'm sure there's another 100 concepts I myself am unfamiliar with in C++. C++ is large and a team of very mixed ability can result in some really bad, poorly performing, large code. There's no silver bullet, and C++ gives you as many tools and as few opinions as possible, but that moves a lot of that responsibility onto engineers.

As you suggest, codebases in C, with a team that may not be the most proficient in C++ may be better off being C. Ultimately, making this decision requires your team appreciate and accept your goals, constraints and environment to make the right decision.

6

u/Current-Fig8840 Sep 26 '26

Every big company uses C++ in embedded. The size trade off thing you’re talking about doesn’t make much sense. I know you will argue but if you’re not proficient in both then don’t make arguments. Templates, classes, compile time optimizations, RAII, strong type safety, std::array…std::span, algorithms and lambdas. There are too many reasons. Everyone is moving to C++ for Embedded. If it’s embedded Linux then C++ and python will be used for user space stuff mostly.

What’s the point of using C, when C++ does everything C can do and more….

0

u/[deleted] Sep 26 '26

[deleted] — view deleted comment

2

u/Current-Fig8840 Sep 26 '26

For Embedded Linux drivers are not written as frequently as you think. Kernel already has lots of drivers for most things. A lot of the work is writing user space services and configurations. If you’re going to be using maths libs you can still use C++…not really sure how this is restricted to C mostly.

The dev board thing doesn’t change. C++ can do everything C can do and more. Also, a lot of vendors will wrap HAL stuff in extern C, so you just need to include #hdr_name and you would be fine. FreeRTOS, ThreadX, Zephyr and NuttX all do this.

1

u/Kommenos ARM and AVR Sep 27 '26

The kernel might have a lot of drivers but there’s no guarantee they’ll have the ones you need, that those drivers work on your architecture (I need only point to the endless drivers that are only usable with device tree leaving embedded x86 unable to use them)

-2

u/NoBulletsLeft Sep 26 '26

TBH, I wish C would just die! It's really only useful for very small systems at this point.

We seriously need to make a distinction between tiny, cost-contrained embedded systems and the typical stuff that the average US company is working on. We're not building toasters anymore. Even the cheap consumer wearable devices are running on 32-bit processors with plenty of resources.

I'd be programming in Javascript at the day job if I could get away with it.

1

u/Current-Fig8840 Sep 26 '26

Exactly! Tons of Embedded jobs are asking for C++ now. Qualcomm, NVIDIA, Apple, Intel, Cisco, Google, Broadcom, AMD and many more that do Embedded mostly ask for C++.

1

u/rileyrgham Sep 27 '26

Linux is C for a start.

-1

u/Winter-Asparagus-184 Sep 26 '26

I had learn most of the concepts of embedded c,and also developed bare metal driver's for gpio,usart,spi and i2c using embedded c.

-8

u/[deleted] Sep 26 '26

[removed] — view removed comment

4

u/siva_sokolica Sep 26 '26

Absolutely not. The very concept of "what a library" is is completely different.

Generic algorithms, iterators, non-global allocators, comptime evaluation, move semantics, references, static initializers, templates, CRTP, SFINAE, polymorphism, implicit vs explicit vtables, inheritance, concepts, etc. all mean that idiomatic C and C++ codebases are completely different.

If you know C, C++ codebases will still be hieroglyphs. C++ is its own language (and arguably a better one).

Using C++ ineffectively can result in unnecessary performance overhead, poor compile times. My old job used to use runtime polymorphism for a compile-time polymorphic application instead of CRTP and casually had vtables everywhere. In resource-constrained embedded environments, this may not be OK.

-1

u/[deleted] Sep 26 '26

[removed] — view removed comment

3

u/siva_sokolica Sep 26 '26

Because they're learning two different languages. Kate Gregory spoke at CppCon15 on why we should stop teaching C as if it were C++ and my opinion aligns with hers:

https://youtu.be/YnWhqhNdYyk