5 ms·
> You cannot also use stdio and most stdlib, so what? You can still use a subset of stdio and stdlib. Newlib also provides hooks you can use to implement fopen
by scoutt 4y ago
> You cannot also use stdio and most stdlib, so what?
You can still use a subset of stdio and stdlib. Newlib also provides hooks you can use to implement fopen and the like, if you want.
> better safety options
Safety is not always the utmost priority. At least, not that kind of safety. It seems people forget this concept from time to time.
> templates instead of undebuggable macros
This is if you use complex macros, which is not always the case. I've been doing embedded for 20 years and I rarely (very rarely) find problems with macros.
But you know what's undebuggable on embedded? Complex inheritance, which sooner or later you'll hit with OOP.
For a system in which you don't have a screen, or logs, or any kind of output, that is usually not in your table, and you have to study failures by telling someone to look at an LED, or by guessing what could have gone wrong, you have to keep your system simple.
Add templates to the mix and good luck opening the project six months later, when a customer calls with a problem.
Edit: But again, used with caution, C++ can be used in embedded, at least the way I use it, as explained before.
- pjmlp 4y agoThe same subsets are available in C++ as well, with stronger type checking and RAII for closing those handles. Yeah, safety and IoT unfortunately aren't something that go together. Using C++ doesn't require OOP all over the place, nor crazy template metaprogramming. The same reason you give for using macros.
- scoutt 4y ago> RAII C++ is used mostly with exceptions disabled on embedded, so failing constructors are a PITA. You have to keep track of valid states with a bool. Now every function entry has: if (!m_bValid) return; I hate it. > Yeah, safety and IoT unfortunately aren't something that go together. Don't forget that IoT is just a minuscule fraction of embedded. Not everything is connected online or requires safety as top priority. > Using C++ doesn't require OOP all over the place, nor crazy template metaprogramming. So we agree. But I think you should be considering the possibility that there might be something going on between you and C, and that it could be possible that not every C developer out there is out of their mind (considering the quantity of past, present and future C projects). Make peace with C, because the world runs on C and we'll be long gone by the time C will be replaced by something else :)
- pjmlp 4y agoIn the history of C++, RAII predates exceptions by several years. When I got introduced to C++, via Turbo C++ 1.0 for MS-DOS in 1993, I decided that there was hardly a reason to use C other than being forced to use it by external reasons. Thankfully there are plenty of places that have moved beyond running on C. :)
- scoutt 4y ago> beyond running on C Can we agree that for at least the past 25 years, 99% of devices runs on C and/or depends on C and/or relies on C, or its development ran/relied/depended on C? From Windows/MacOS/Linux kernels up to the FW in your mouse, keyboard, monitor and HDD controllers. It's difficult to escape C :)
- pjmlp 4y agoUsing C compilers written in C++, yeah really difficult to escape C. Windows has been migrating into C++ since Windows Vista, when VC++ introduced kernel support. Its C universal runtime is written in C++ with extern "C" entry points. Ah and then there is COM/WinRT, also mostly about C++ and .NET, even if the ABI is compatible with C (for masochists). macOS uses C++ for drivers, a kernel without drivers isn't of much use. Speaking of which, in Android all drivers written using Project Treble (required as of Android 8) are either C++ or Java based, and now Rust is also into the picture. The only C is the "classical" Linux upstream stuff.
- OskarS 4y agoYeah, checking return codes is a thing you NEVER have to do in C... The "exceptions are evil, but without exceptions you can't fail a constructor!" is a really irritating canard when it comes to C++. First off all, the terribleness of exceptions is way overhyped, but even if you do want to avoid them, this is not a problem: just use a factory function instead of a constructor and return a `std::optional` (or a default-constructed value and an error code if you want to avoid `std::optional` for some weird reason). I like pure C a lot and it definitely has a place in areas like embedded. But this kind reflexive disdain for C++ using uninformed arguments is really tiresome. C++ is fine.