4 ms·
Isn't this one reason why C is the de facto FFI? OSes happen to use it in their OS ABI and so everything is forced to speak it
by mohamedkoubaa 2mo ago
Isn't this one reason why C is the de facto FFI? OSes happen to use it in their OS ABI and so everything is forced to speak it
- pjmlp 2mo agoOS written the C, which is what many overlook. If you are on e.g. z/OS you would be using ILE, Integrated Language Environment, on ChromeOS JS/WASM, on Android either DEX or JNI,...
- aboardRat4 2mo agoAndroid is Linux and it's written in C. Bionic is still a posix libc.
- pjmlp 2mo agoAndroid uses the Linux kernel as implementation detail, it could be changed with Zircon if Google cared, bionic is partially POSIX, only the required for ISO C, ISO C++, ART and NDK native APIs is exposed. 80% of Android APIs are exposed via Java, and even native ones have to use JNI.
- p_l 2mo agoAdditionally a lot of the APIs if you go underneath, including native code components, are exposed through few variants of Binder (BeOS-derived IPC for the uninitiated) including userspace drivers. Binder APIs very much do not follow C ABI other than the part where you deal with wrapper around ioctl()
- aboardRat4 2mo agoThis is entirely unrelated to the point made. Binder is just C++ with a thin IPC compiler, more or less similar to any IPC idl. Could be sunrpc, but Google wanted a c++ wrapper. But in any case this is completely irrelevant, because there is no such thing as a "userspace driver" (unless you're speaking about hurd or plan9). Drivers are by definition kernel-space code (which on Linux is either built into the kernel, or is a loadable kernel module). Those binder wrappers are just a convenience layer, underneath it's all still Linux, /dev/video0, v4l2, and so on.
- p_l 2mo agoLinux actually has pretty long history of userspace drivers, and multiple kernel drivers have as their main if not only logic a way to link hardware interface with userspace app, or just providing transport interface. And android heavily uses such interfaces from day 0, which is why you have separate binder instance on Android for drivers. As for Binder being C++, no it isn't. Historically it has connection with C++ due to how it was used, but like other IPC it's not bound to C++, and arguably given how it is structured compared to some other options there's even less C++ specific stuff in it. Also, IIRC the use of Binder predates acquisition of Danger (?) by Google
- aboardRat4 2mo agoIt's just demagoguery. Windows could switch to Linux kernel if Microsoft cared enough to invest into Wine. But this will not happen any time soon. All smartphone drivers would have to be rewritten for a different kernel.
- bluGill 2mo agoOne reason. The other is C is easy. Any language can implement it and have confidence it can work. (there are other options that are just as easy, but C won). C++ is much harder because of things like function overloading and exceptions - none of it is difficult, but there is a lot more to do and thus more opportunities for bugs.
- mohamedkoubaa 2mo agoI would go far as to say that modern C++ is an Eldritch horror of a programming experience
- pjmlp 2mo agoUnfortunately no one is going to rewrite LLVM, GCC, CUDA, DirectX, Metal, SYSCL, V8,... into something else. Same applies to C and UNIX/POSIX, OpenGL/Vulkan/OpenCL/NVN/LibGNM(X),... Thus analysers and language subsetting tools, enforcing language style guides and safer coding practices.
- rramadass 2mo agoOh come on; that is BS and you know it. It is complex/complicated/baroque but for the power, flexibility, real-world-usage that it provides it is worth the effort. The mistake that people make is to try and learn it all at the same time which overwhelms them. Use a good book like Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers by Peter Gottschling and you should have no problem at all.
- mohamedkoubaa 2mo agoFor context: I have over a decade of professional experience with c++ in large scale software projects and it is by far the language over which I have the most mastery.
- rramadass 2mo agoAnd yet you make such statements ;-) I often see on HN these sorts of comments whenever C++ is brought up and it really needs to stop. It is wrong, adds no value to the discussion and does a grave injustice to the programming community. We should be encouraging programmers to learn C/C++ since just knowing those two languages enables one to program MCU/embedded/desktop/server machines across all layers of software from apps/scientific software/OS/system software/bare-metal in the real-world. One can imagine the job opportunities for a programmer with such a skillset as market needs change. With both Hardware and Software evolving so rapidly nowadays, C/C++ are the one constant interface language in the industry.