Objective C vs C for kernel space?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
thomashc
Posts: 2
Joined: Wed Jun 03, 2009 8:19 pm

Objective C vs C for kernel space?

Post by thomashc »

Which would be better? Me and a few others are writing a kernel and we'd like to know how C stacks up against Objective-C. None of us really like C++.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Objective C vs C for kernel space?

Post by Firestryke31 »

IMO Obj-C is C++ with a bizarre syntax. There are probably things native to Obj-C that C++ doesn't do, just like there are probably things C++ does that Obj-C doesn't do.

Given the choice, I personally would choose C++ due to the not-freakish syntax, but that's my choice.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
thomashc
Posts: 2
Joined: Wed Jun 03, 2009 8:19 pm

Re: Objective C vs C for kernel space?

Post by thomashc »

Thanks, but like I said we DO NOT want to use C++.
Mainly we will probably end up using C and Objective C. However, we'd like to know which would be better for kernel space.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Objective C vs C for kernel space?

Post by whowhatwhere »

thomashc wrote:Thanks, but like I said we DO NOT want to use C++.
Mainly we will probably end up using C and Objective C. However, we'd like to know which would be better for kernel space.
Don't.

For one, the runtime itself is over 800KB of just source code in C. Then add all the extras and it's a waste.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Objective C vs C for kernel space?

Post by Firestryke31 »

Any particular reason you don't want to use C++? It's not like it's any harder to write the kernel in than C, and you don't have to implement the entire std namespace just to get the kernel working.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Objective C vs C for kernel space?

Post by kop99 »

Any way, linux kernel is made by c.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Objective C vs C for kernel space?

Post by Solar »

Not much of an argument, that one. Hey, Singularity is written in C#. So what?

But I'd advocate for C, too, if only for the sheer popularity of the language. In the very least, there are many more people competent to help you with a C problem than there are for Obj-C.
Every good solution is obvious once you've found it.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Objective C vs C for kernel space?

Post by Colonel Kernel »

The Objective-C syntax is ok once you get used to it. I actually find it helpful to have whitespace between objects and methods to emphasize that they are not tightly bound to one another. Also, the square brackets remind me of envelopes -- a nice visual reminder of the message-passing nature of the language. :) YMMV.

However, I don't think using Objective-C in a kernel is at all useful. BTW, this has all been discussed before here:

http://forum.osdev.org/viewtopic.php?f= ... bjective+C

@Solar: C# has something important that Objective-C lacks: A very large subset that is verifiably type-safe. Also, its virtual method dispatch speed is on par with that of C++, while Objective-C message passing is quite a bit slower, although more flexible. However, in a kernel the speed is more important than the flexibility.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Re: Objective C vs C for kernel space?

Post by inx »

Firestryke31 wrote:IMO Obj-C is C++ with a bizarre syntax.
IMO C++ is Obj-C with a bizarre syntax. Any C source compiles perfectly as objective C, they just added classes and the supporting
syntax. C++ not being any harder is entirely dependent on your background. C++ is not simply an extension to C, it is its own
C-like language.

That aside, I do agree that Objective-C is probably a waste for in-kernel use. Objective-C is very introspective, which takes a lot
of runtime support, and allows for a lot of flexibility. This is why the runtime is so gargantuan, and also why it doesn't make much
sense for kernel mode.

While you could write a pared down runtime that does not support a lot of the introspection and dynamism which is part of
Objective-C, you would most likely end up having to do major modifications to the compiler just to remove functionality.
Personally, my way around this has been to just use C in an object-oriented manner in-kernel, and Objective C in userland.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Objective C vs C for kernel space?

Post by Solar »

I always enjoy a discussion on the pro's and con's of programming languages, as you tend to learn some from them. Like, that C source can be compiled with an ObjC compiler.

But that's also true for C source and a C++ compiler, by design, so I don't think it's fair to say that ObjC is an extension to C while denying C++ that label.
Every good solution is obvious once you've found it.
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Re: Objective C vs C for kernel space?

Post by inx »

Solar wrote:But that's also true for C source and a C++ compiler, by design, so I don't think it's fair to say that ObjC is an extension to C while denying C++ that label.
That was ignorance on my part, I was not aware of that. Thank you for the clarification.

I kind of messed with picking up C++ a few years back, and thought I remembered some sort of odd casting problem, but I tested a couple things, and
it was entirely a misconception on my part. I probably just had some difficulty with operator overloading or something. Never did quite understand the
point of that.

Anyway, looking at it from this renewed viewpoint, Objective C's syntax is more bizarre than C++'s, coming from a C function-calling standpoint. On the
other hand, however, as Colonel Kernel pointed out, sending a message to an object in Objective C is not cognate to calling a method in C++. There
are fundamental differences in the underlying architecture, which again comes back to Objective C's massive runtime dependence and the more
active participation of the Objective C runtime compared to most other compiled languages.

</thread hijacking> =p
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Objective C vs C for kernel space?

Post by quanganht »

C is better choice
"Programmers are tools for converting caffeine into code."
User avatar
steveklabnik
Member
Member
Posts: 72
Joined: Wed Jan 28, 2009 4:30 pm

Re: Objective C vs C for kernel space?

Post by steveklabnik »

Solar wrote:But that's also true for C source and a C++ compiler, by design, so I don't think it's fair to say that ObjC is an extension to C while denying C++ that label.

Objective C is a strict superset of C, whereas C++ is not. Therefore, Objective C is a C extension, and C++ isn't. It's a pretty fair thing to say.


That said, while Objective C is a pretty cool language, I'm not sure that it'd really be any better than just straight up C for kernel development. That shouldn't stop you from doing so, though...
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Objective C vs C for kernel space?

Post by whowhatwhere »

When I was interested in kernel-space Objective-C, I had an idea for method dispatch that used co-routines that I thoroughly believed would be faster and better suited to system-level programming. Then I saw the runtime and how many ugly hacks were put to use just to make it work with obscure architectures and quickly put down that idea. Don't try it, believe me. It's horrid.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Objective C vs C for kernel space?

Post by Solar »

steveklabnik wrote:Objective C is a strict superset of C, whereas C++ is not. Therefore, Objective C is a C extension, and C++ isn't.
Because you say so, or because of some facts you're just not willing to share with us?
Every good solution is obvious once you've found it.
Post Reply