Objective C vs C for kernel space?
Objective C vs C for kernel space?
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++.
- Firestryke31
- 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?
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.
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?
Re: Objective C vs C for kernel space?
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.
Mainly we will probably end up using C and Objective C. However, we'd like to know which would be better for kernel space.
-
- Member
- Posts: 199
- Joined: Sat Jun 28, 2008 6:44 pm
Re: Objective C vs C for kernel space?
Don't.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.
For one, the runtime itself is over 800KB of just source code in C. Then add all the extras and it's a waste.
- Firestryke31
- 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?
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?
Re: Objective C vs C for kernel space?
Any way, linux kernel is made by c.
Re: Objective C vs C for kernel space?
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.
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.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Objective C vs C for kernel space?
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.
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:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re: Objective C vs C for kernel space?
IMO C++ is Obj-C with a bizarre syntax. Any C source compiles perfectly as objective C, they just added classes and the supportingFirestryke31 wrote:IMO Obj-C is C++ with a bizarre syntax.
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.
Re: Objective C vs C for kernel space?
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.
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.
Re: Objective C vs C for kernel space?
That was ignorance on my part, I was not aware of that. Thank you for the clarification.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.
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
Re: Objective C vs C for kernel space?
C is better choice
"Programmers are tools for converting caffeine into code."
- steveklabnik
- Member
- Posts: 72
- Joined: Wed Jan 28, 2009 4:30 pm
Re: Objective C vs C for kernel space?
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...
-
- Member
- Posts: 199
- Joined: Sat Jun 28, 2008 6:44 pm
Re: Objective C vs C for kernel space?
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.
Re: Objective C vs C for kernel space?
Because you say so, or because of some facts you're just not willing to share with us?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.
Every good solution is obvious once you've found it.