8 ms·
Right -- Android does have a C API but it’s a pain to use and really incomplete: https://developer.android.com/ndk/guides/stable_apis https://developer.android.
by iainmerrick 3y ago
Right -- Android does have a C API but it’s a pain to use and really incomplete: https://developer.android.com/ndk/guides/stable_apis https://developer.android.com/ndk/guides/stable_apis If you want to do anything else you need JNI which is an even bigger pain.
I don’t really understand why the Android team haven’t made it easy to call any Java API from C, with auto-generated bindings or some such.
I think they just don’t believe in apps using native code, beyond the special case of games (note that pretty much all the native APIs are to do with low-level graphics and sound).
- pjmlp 3y agoYou don't need to wonder, it is quite explicity mentioned on the NDK documentation. "The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages." -- https://developer.android.com/ndk https://developer.android.com/ndk "The NDK may not be appropriate for most novice Android programmers who need to use only Java code and framework APIs to develop their apps. However, the NDK can be useful for cases in which you need to do one or more of the following: - Squeeze extra performance out of a device to achieve low latency or run computationally intensive applications, such as games or physics simulations. - Reuse your own or other developers' C or C++ libraries. " -- https://developer.android.com/ndk/guides https://developer.android.com/ndk/guides There is also the security aspect, why they discourage the use of those languages for full blown applications.
- iainmerrick 3y agoHmm, that explains the situation (native code is discouraged for most purposes) but doesn’t explain why they take that approach. There is also the security aspect, why they discourage the use of those languages for full blown applications. Native code in apps doesn’t seem like a security problem on iOS, though?
- pjmlp 3y agoWhy do you think Swift was invented, and there is a Safe C dialect used on iBoot? Spend some time reading iOS security updates from Apple, lots of nice CVEs fixes reported there.
- iainmerrick 3y agoSwift compiles to native code. C and C++ are well-supported userspace languages on iOS.
- pjmlp 3y agoJava also compiles to native code on Android. Try to write an iOS application using only C and C++, instead of either Objective-C or Swift. "Swift was designed from the outset to be safer than C-based languages, and eliminates entire classes of unsafe code" -- https://www.swift.org/about/#features https://www.swift.org/about/#features "Swift is a successor to the C, C++, and Objective-C languages. It includes low-level primitives such as types, flow control, and operators. It also provides object-oriented features such as classes, protocols, and generics, giving Cocoa and Cocoa Touch developers the performance and power they demand." -- https://developer.apple.com/swift/#fast https://developer.apple.com/swift/#fast Some of the information related their Safe C dialect, https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-c-fbounds-safety/70854 https://discourse.llvm.org/t/rfc-enforcing-bounds-safety-in-... "2023 EuroLLVM - Keynote: “-fbounds-safety”: Enforcing bounds safety for production C code" https://www.youtube.com/watch?v=RK9bfrsMdAM https://www.youtube.com/watch?v=RK9bfrsMdAM Finaly a recent gem from CppNow 2023, "Introducing a Memory-Safe Successor Language in Large C++ Code Bases" https://www.youtube.com/watch?v=lgivCGdmFrw https://www.youtube.com/watch?v=lgivCGdmFrw
- iainmerrick 3y agoThe only point I’m trying to make is that C and C++ are well supported on iOS -- they work out of the box with the standard dev tools and there are plenty of Unix system libraries (e.g. libcurl). On Android, C and C++ are very much second class citizens. I find that a strange decision.