3 ms·
C++ as OS APIs (which so far only Microsoft seems to do in their UWP wrapper APIs, which is a fairly exotic use case) can be dealt with the same way as Objectiv
by flohofwoe 6y ago
C++ as OS APIs (which so far only Microsoft seems to do in their UWP wrapper APIs, which is a fairly exotic use case) can be dealt with the same way as Objective-C on macOS and iOS: put all the code which talks to OS APIs into separate C++ or Obj-C source files, and put that code behind a simple C-API.
It's also interesting to note that Microsoft is only using header-only C++ wrappers, under the hood it's all plain old C-APIs via COM (because it would be a bad idea to expose C++ APIs in system DLLs).
The usage rules for C++ in Google's Fuchsia are so limited [1] that it is essentially a "C with classes", and it also has the rule that all shared libraries must have C APIs. I really don't see the advantage of using C++ for the underlying implementation compared to plain C if C++ has to be stripped down that much, and the public APIs are C APIs anyway.
[1] https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/...
- pjmlp 6y agoCOM with C is just for masochists, and no UWP is not exotic, all new Windows APIs since Windows 8 are mostly UWP, with Win32 frozen in Windows XP, given that Vista basically rebooted Longhorn features as COM/.NET instead of pure .NET components. Header only libraries are a stop-gap solution until modules are fully done, then good luck with those C bindings into .NET metadata used by UWP. Regarding Android and Fuschia, C++ with classes is still better than plain old unsafe C and if you cannot see the safety that C++ brings into C, then one more reason why those companies are on the good path to remove C as an option.
- gpderetta 6y agoDoesn't seem extremely limited at all: - Exceptions, RTTI, thread_local, Statically constructed object all require runtime support and are problematic in a kernel so it is not surprising - Virtual inheritance: almost litterally nobody uses it. - initializer lists require static storage which is also problematic in a kernel - operator overloading and trailing return types are a stylistic choice, but at the end of the day they are a tiny bit of C++ Things that are allowed: actual OO classes inheritance (including multiple inheritance), virtual functions, RAII, templates (no restrictions at all), lambdas, all the recent goodies. I.e. all the things that make C++, well, C++. So it is way less restricted than other guidelines I have seen for well known C++ projects.