4 ms·
This is slightly beside the point, but those stack traces are C++ functions. I was pretty surprised by that (though, granted, I don't know anything about macOS
by OskarS 5y ago
This is slightly beside the point, but those stack traces are C++ functions. I was pretty surprised by that (though, granted, I don't know anything about macOS internals). I would have expected either pure C for the kernel, or maybe Objective-C if they wanted a higher level language. They don't really have any C++ in their operating system APIs, right? Like, if you interface with Core <Whatever>, isn't that all C, Objective-C and Swift? Is there a lot of C++ in the macOS kernel/userspace?
- saagarjha 5y agoIOKit in the kernel is a C++ API; the userspace version is C.
- irae 5y agoThey are still a fork of BSD, so it stands to reason that the team working for years on kernel and lower level parts of the OS still uses C++.
- TickleSteve 5y agoMach is not a fork of BSD. The kernel is Mach (Hybrid microkernel) supporting a BSD API.
- astrange 5y agoThere is a lot of FreeBSD in the kernel/libc/userland. BSD doesn't use C++ though, they use C.
- galad87 5y agoI don't know how many, but a good number of frameworks are C++ internally, for example WebKit, the Objective-C runtime itself, IOKit uses a subset of C++, Metal Shading Language is a subset of C++.
- gurkendoktor 5y agoThere is (was?) always a lot of C++ in Core Animation stacktraces, and Core Animation was really foundational to the iPhone UI.
- jjoonathan 5y agoYeah, the "driver" parts of Mac OS X -- the bits that aren't Mach or BSD -- use a restricted subset of C++. It doesn't carry over into userland. Not much, anyway. I know that C++ is out of vogue, but last time I wrote drivers in linux and OSX (10 years ago) I left with the distinct impression that it was oversold, at least compared to C. C clunks hard and C++ addresses the worst of it. I've never had to corral a bunch of overzealous junior C++ programmers, which I suspect is where the C++ reputation comes from, but Apple went down that path and wound up with something pretty decent. IMO today it's a shrug and 25 years ago it was forward looking.
- zozbot234 5y agoLinux devs are working to support Rust, which is a lot cleaner than C++ (essentially, no implementation inheritance) and has more straightforward interfacing with C components.
- StillBored 5y agoSelective implementation inheritance is actually quite useful for kernel/driver development if its used where function pointers in C tend to be used. Pluggable interfaces. It standardizes the syntax, provides default implementations, and forces implementation of mandatory methods. C++ when used as a better C, really is better.
- zozbot234 5y agoPluggable interfaces are ok, and Rust supports them just fine via traits. Actual implementation inheritance is inherently anti-modular.
- jjoonathan 5y agoI'm not convinced that "no inheritance" is better -- drivers seem to be one place where it's actually put to good use -- but I also don't think it really matters that much. In contrast, Rust definitely has fewer foot-guns, and that matters a lot. Of course, the OSX driver code is going on 25 years old, so it's not evidence of anyone's opinion that C++ beats Rust for OS dev.