14 ms·
Any ideas where to start learning C++ as an embedded developer? I wrote many lines of bare metal C code and want to transit to higher level jobs. I see many exp
by lnsru 3y ago
Any ideas where to start learning C++ as an embedded developer? I wrote many lines of bare metal C code and want to transit to higher level jobs. I see many expensive or completely free courses, but I am not sure which one is usable in my complicated situation.
- robinhola 3y agoI’d recommend reading Effective C++ books from Scott Meyers and trying to interview for the jobs you’re looking for over taking a course!
- indigo945 3y agoWell, you seem to be precisely the target audience for the course linked in this very post: > This open-access course is directed at those who are already familiar with C > and object-oriented programming towards a proficiency level of C++ > programming.
- tialaramex 3y agoMaybe, in this context it makes lots of sense, if you know C well there are things which "just work how you expect" in C++ and so they need at most a brief refresher. I agree with Kate Gregory that this is a bad way to teach C++ from scratch. That is, if you know only say, Python or Java (or nothing) and want to learn C++, you should not begin by learning C. Kate's approach skips many of the things you can do in C++ but you shouldn't, whereas if we try to start with C you're going to see that a lot, because "they were legal in C" is why they're allowed in C++ even though they're a bad idea and then you have to unlearn things. You're maybe expecting some of that if you've years of C programming experience, but there's no need to introduce an idea on Monday only to tell students on Tuesday that it's a bad idea and they must never do that. The most insidious cases are where something is legal and correct in C but it's wrong in C++ yet it will compile and you maybe have broken software. There are some nasty type punning examples, where the pun was an idiomatic C expression which does exactly what you wanted, but in C++ that's Undefined Behaviour and all bets are off. You'd just never teach those type puns in a pure C++ course, they're never the Right Thing™.
- zedgondal 3y agoCan you maybe share some paid/unpaid resources to learn C++ from scratch for someone coming from Java and JS?
- tialaramex 3y agoKate has a PluralSight course which I have watched (not really to learn C++ but to see her approach) and that seemed decent to me, although of course I can't vouch for it having taught what you'd need coming from Java and JS, not least because my background is far more polyglot including Scheme and the Standard ML for example. I definitely think Bjarne Stroustrup's book about his own language isn't very good, even in later editions (which correspond to a more modern language) and so I would avoid buying that, I'm not sure it's a good defence of the language as an idea and I'm sure it isn't an effective tutorial, even if not for being out-of-date.
- butlerm 3y agoThere is a considerable divergence of opinion on that subject. In my view, C++ isn't remotely suitable as a programming language for someone without a healthy understanding of C. Perhaps a dialect of C++ could be developed that was more of a cousin to Rust, but C++ as we know it is a C like programming language with a very large number of features added and all the ways to fail just like a C program does. There are real world advantages of course, but it is not a language for the faint of heart, not even close.
- rramadass 3y ago> C++ isn't remotely suitable as a programming language for someone without a healthy understanding of C. I always look askance at folks who say they know C++ but not C. The C++ abstract machine is built over the C abstract machine and it becomes even more clearer when you go down to the binary level.
- gpderetta 3y agoDepends what you mean by "understand C". As you say, understanding the C abstract machine and memory model is critical for a C++ programmer. Understanding C idioms, the standard library, best practices, and general C software architecture , is less important if not downright negative early in your formation. You will end up picking a lot up anyway if you stick to C++ long enough.
- lnsru 3y agoI will go through the course before Xmas. The thing is that in bare metal development even C standard library is not always being used. Recently I wrote some string processing functions for very specific parsing task. Nobody would need such crap while working with operating system.
- HankB99 3y agoThat doesn't address the constraints that are typical in embedded systems such as limited memory (RAM) and the expectation that a program will run forever. There are resources oriented toward embedded C++ that address these (at least memory allocation.) On a project a couple years ago I was pushing to use C++ instead of C, if only as a "C compiled using the C++ compiler" for better type checking. I could not convince the project lead, who's technical depth far exceeded mine, that the C++ compiler was as likely as the C compiler to produce correct translations.
- gosub100 3y agoI wouldn't worry about the compiler producing correct code, I would worry about the heap eventually fragmenting enough that an allocation fails (perhaps thousands of hours after the program launches). I know C++ offers the ability to supply your own allocator, but it's not for the faint of heart.
- rajeevk 3y agoIf you want to understand the C++ in terms of C code then probably you would need to understand the C++ object model. I mean, how C++ classes are translated into C equivalent code. If you are interested in these you can take a look at a tutorial I wrote long back https://www.avabodh.com/cxxin/cxx.html https://www.avabodh.com/cxxin/cxx.html If you want to write bare metal C++ then this page from the above tutorial will be useful https://www.avabodh.com/cxxin/nostdlib.html https://www.avabodh.com/cxxin/nostdlib.html
- ptero 3y agoIf you want to transit to higher level jobs you may get better mileage out of broadening to other languages (e.g., python) or skills (e.g., project management) than from a C to C++ transition. My 2c.
- rramadass 3y ago1) Real-Time C++ by Christopher Kormanyos. - For using C++ in embedded systems. 2) Software Architecture with C++ by Adrian Ostrowski and Piotr Gaczkowski. - Gives the overall picture of how to use C++ plus relevant modern tools as a complete development system. 3) The C++ Programming Language by Bjarne Stroustrup. - The bible/reference with programming techniques for the language. Learning C++ is not difficult and don't let the size of the language intimidate you. Survey the different ways of programming in C++ i.e. Imperative/Object-Oriented/Generic/Meta-programming and use them as needed in your project without trying to master everything; that will only happen over time as you gain more experience.
- deleted 3y ago[deleted]
- maldev 3y agoIt depends on what you target. I do alot of Kernel and really low level C++, and it's a completely different style than even app dev, so you have to be sure you don't go down the completely wrong route. For my target space, there's a few rules for c++. Footguns: A. No STL, it causes to much bloat when binary size is critical. B. (almost) No inheritance or virtual functions. Again, it causes some bloat and adds in some instructions and code to support these features that can cause issues in low level environments. Things to learn (All work in the kernel): A. Learn templates, especially c++20. Templates add ZERO bloat, they literally just generate the function again with proper types the same way a macro would. B. Use RAII. C. Use constructors and overloading. D. Zero pointers should be exposed to code except where absolutely needed. If you need to pass by reference, use the c++ style. E. All allocations should be wrapped in a class with RAII. You can overload the operators on the class to make it seem like a pointer so you can still do if(!RAIIPointer). A good video on kernel c++ is here https://www.youtube.com/watch?v=AsSMKL5vaXw https://www.youtube.com/watch?v=AsSMKL5vaXw . You can use a surprising amount of C++ language features in the kernel and it makes it extremely smooth and safe if you do it properly.
- manonthewall 3y ago[dead]
- Leherenn 3y agoI would add constexpr (I guess it might be included with templates?). You can do some nifty stuff like generate CRC lookup tables at compile time without hardcoding them.
- maldev 3y agoYes! 100% Right, can't believe I left that out. One of the big things is to make sure to use ConstEval if you can do a new verson of c++(20), since ConstExpr isn't guaranteed and can leave stuff in the binary that can hurt size or obfuscation. For example one thing I see alot is lookup tables for hashing who use constexpr and hide some key data in there, but it "may" just randomly do it, and can cause alot of issues.
- ska 3y agoDo you want to do embedded/low level c++, or are you looking to transition out of that?
- lnsru 3y agoI will get out. Application development using C++ and Python. Maybe C#.
- nuancebydefault 3y agoThis is maybe a very unpopular opinion, but if you go from C to a higher level language, I would advise to steer away from C++, certainly if it's would be your first OO language.
- aa-jv 3y agoYou can definitely start putting C++ into your embedded projects, and get familiar with things in an environment in which you're already operating. A lot of great C++ code can be found with motivated use of, for example, the platformio tooling, such that you can see for yourself some existing C++ In Embedded scenarios. In general, also, I have found that it is wise to learn C++ socially - i.e. participate in Open Source projects, as you learn/study/contribute/assist other C++ developers, on a semi-regular basis. I've learned a lot about what I would call "decent C++ code" (i.e. shipping to tens of thousands, if not hundreds of thousands of customers) from such projects. I would suggest finding an open source C++ project, aligned with your interests, and study the codebase - as well as the repo history (i.e. gource) - to get a productive, relatively effortless (if the interests align) boost into the subject. (My particular favourite project is the JUCE Audio library: https://juce.com/ https://juce.com/ .. one of many hundreds of great projects out there from which one can also glean modern C++ practices..)