8 ms·
> C++ was huge back in 1998, now it's bloody massive. I don't think any "run-time" feature was added since, though. It's all either OS support (<thread>, etc,
by jcelerier 9y ago
> C++ was huge back in 1998, now it's bloody massive.
I don't think any "run-time" feature was added since, though. It's all either OS support (<thread>, etc, that you wouldn't use in-kernel anyways) or template stuff that has 0 impact on runtime (and actually sometimes helps decreasing code size).
https://istarc.wordpress.com/2014/07/18/stm32f4-oop-with-embedded-systems/ https://istarc.wordpress.com/2014/07/18/stm32f4-oop-with-emb...
https://www.embedded.com/design/programming-languages-and-tools/4438660/Modern-C--in-embedded-systems---Part-1--Myth-and-Reality https://www.embedded.com/design/programming-languages-and-to...
https://hackaday.com/2015/12/18/code-craft-embedding-c-templates/ https://hackaday.com/2015/12/18/code-craft-embedding-c-templ...
If some guys are able to run c++ on 8kb microcontrollers, there's hardly a non-political
reason it couldn't be used in-kernel.
See also IncludeOS: http://www.includeos.org/ http://www.includeos.org/
- alxlaz 9y agoAdditions have certainly been made since back in 1998 (things like smart pointers are relatively new on this scale, as far as I know). Many runtimes for resource-constrained embedded systems do not support all of C++'s features. Exceptions are the most usual omission. You can certainly strip things down to a subset that can fit 128K of flash and need only 1 or 2K of RAM at runtime, but the question is not only one of computational resources used for the library itself. Additional code always means additional bugs, the semantics sometimes "hide" memory copying or dynamic allocation in ways that many C++ programmers do not understand (and the ones who do are more expensive to hire than the ones who do not), and so on. You can certainly avoid these things and use C++, but you can also avoid them by using C. I agree that mistrust and politics definitely play the dominating role in this affair though. I have seen good, solid, well-performing C++ code. I prefer C, but largely due to a vicious circle effect -- C is the more common choice, so I wrote more C code, so I know C better, so unless I have a good reason to recommend or write C++ instead of C, I will recommend or write C instead. I do think (possibly for the same reason) that it is harder to write correct C++ code than it is to write correct C code, but people have sent things to the Moon and back using assembly language for very weird machines, so clearly there are valid trade-offs that can be made and which include using language far quirkier than C++.
- cmrdporcupine 9y agoI absolutely do not understand your point. Anybody doing OS development in C++ is doing so with absolutely no C++ standard library support, same as if you were using C++ to develop for your microcontroller. If C++ binaries are compact enough for Arduino or Parallax Propeller development (<32KB RAM), they are absolutely fine for kernel development. The real answer is historical, and cultural. On the latter, Unix is a product of C (well, and BCPL) and C is a product of Unix. They two are intertwined heavily. The former is as was mentioned a product of the relative crappiness of early C++ compilers (and the overzealous OO gung-ho nature of its early adopters perhaps as well...) C++ without exceptions, RTTI, etc. has a lot to offer for OS development. Working within the right constraints it can definitely make a lot of tasks easier and cleaner. It won't happen in Linux, tho.
- pjmlp 9y agoAnd lets not forget C++ got created, because Bjarne didn't want to touch C after his experience going from Simula to BCPL, but it had to be compatible with AT&T official tooling.
- CyberDildonics 9y ago> Additional code always means additional bugs What additional code? > You can certainly avoid these things and use C++, but you can also avoid them by using C. Right, but what you can't get with C is destructors and move/ownership semantics. > I do think (possibly for the same reason) that it is harder to write correct C++ code than it is to write correct C code The ability to write typesafe data structures with move/ownership semantics and specified interfaces while being a superset of C would lead some to say that this is not true.
- alxlaz 9y ago> What additional code? All the code that you need in order to support smart pointers, templates, move/copy semantics, exceptions and so on. To paraphrase someone whose opinions you should take far more seriously than mine, you can't just throw Stroustrup's "The C++ Programming Language" on top of an x86 chip and hope that the hardware learns about unique_ptr by osmosis :-). There used to be such a thing as the sad story about get_temporary_buffer ( https://plus.google.com/+KristianK%C3%B6hntopp/posts/bTQByU1iWGK https://plus.google.com/+KristianK%C3%B6hntopp/posts/bTQByU1... -- not affiliated in any way, just one of the first Google results). The same goes for all the code that is needed to take C++ code and output machine language. In my whole career, I have run into bugs in a C compiler only three or four times, and one of them was in an early version of a GCC port. The last C++ codebase I was working on had at least a dozen workarounds, for at least half a dozen bugs in the compiler.
- baby 9y ago> 0 impact on runtime (and actually sometimes helps decreasing code size) beware, performance and code size does not always go hand in hand! https://channel9.msdn.com/Events/Build/2013/4-329 https://channel9.msdn.com/Events/Build/2013/4-329