Hacker News new | ask | show | jobs
by calloc 5147 days ago
Objective-C isn't used in XNU the kernel that Mac OS X uses, Mach is a mixture of C and C++ (A subset of it actually, known as IOKit).
1 comments

System programming is more than just the kernel.

I imagine that the kernel can easily compiled with the Objective-C or Objective-C++ compiler, if Apple so wishes.

You "imagine" incorrectly. A functioning Obj-C requirement requires a runtime. Currently that runtime (libobjc) is written in C, and it requires a C library to function. Yes, you can rewrite those portions to use only functions available in kernel-land, but it is by no means "easy" as you suggest.
This just goes to show you don't understand compilers.

All languages require runtimes, even C. The thing is that C as high level assembler it is, uses the operating system as its runtime.

The C language is also part of Objective-C, in a similar vein as C++ also supports most of the C89 features with small exceptions.

So it is possible to have the Objective-C runtime compiled using the C subset of Objective-C. This is known as compiler bootstrapping.

This just goes to show you don't understand compilers.

No, admittedly, I don't, at any more than a basic level. But you're still wrong.

Try compiling, linking, and running an ObjC program without the ObjC runtime. See how that fails. See how long it takes you to write a minimal runtime that can run your program in user-space, and then kernel-space. It won't be quick.

Try compiling, linking, and running a plain-vanilla C program without the "C runtime" (I guess you mean a combination of libc, libgcc, and crt.o, basically what you get when you pass -nostdlib -nostartfiles to gcc). Yep, that'll fail too. Then get it to compile and run anyway. Not that hard.

That's* the difference I'm talking about.

At the very least, kernels like Linux and Mach/Darwin already have kernel-friendly replacements for the libc functionality they commonly use. Doing something similar for ObjC would be time consuming. Certainly it isn't impossible, but note that I never said that: I merely pointed out it wasn't easy.

C hardly requires it's runtime. Objective-C without the runtime is just C, if you write the runtime, GC, and other low-level system components in the C subset of Objective-C you are just writing the kernel in C.
Technically you will be using the Objective-C compiler, so it is still Objective-C even if the syntax looks like C.

The same applies if you would be using the C subset of a C++ compiler.

This is in the original context of how all systems will be written in "GC enabled system programming languages". If the language is not GC enabled due to missing a runtime or w/e then the technicality isn't relevant.