Re:Modern C++ for C Programmers (2018)
by beached_whale on Friday July 23, 2021 @10:18PM
(#27937870)
I do a lot of static_asserts and small composable constexpr methods so that when I am wrong I get a compile failure. Actually with IDE's I get a little overlay telling me the error usually.
Constexpr methods seem perfect for embedded in a lot of ways too. Yes, I won't be touching real memory or ports, but I can ensure that the method isn't doing silly things either. Having a memory address class that filters on the proper operations and only allows them is awesome. Saw a good video on the topic recently too https://www.youtube.com/watch?v=fsMmh8F8uV0
Re:Modern C++ for C Programmers (2018)
by osivertsson on Friday July 23, 2021 @10:24PM
(#27937891)
Except that most devs don’t understand what their C++ code actually does at runtime and many try to be too clever and use too many features. I have seen spectacular failures regarding memory usage and copies, static initializers, even exceptions (just design your APIs without them!)
C++ code bases may have less buffer overflows and off-by-one errors but I don’t trust them unless they come with an extensive safety-net in the form of unit-tests with good coverage.
Embedded programming in C++ is pure fun. The more modern your code is, the less room you leave for bugs: when it compiles, it mostly works. Where it doesn't, it shows up in your logic, not in random memory corruption.