Can a whole operating system be written without using even one line of C/C++ code?
EDIT: One more to add to the list - assembly
Most of the operating systems are written in the C/C++ languages. These not only include Windows or Linux (the Linux kernel is almost entirely written in C), but also Google Chrome OS, RIM Blackberry OS 4.
There is no limit, but keeping maintainability in mind around 30 lines max. Should be used if possible.
It's closeness to the hardware, explicit memory management feature, flexible structure, compatibility, and portability makes it the ideal choice for low-level development such as operating systems and embedded software.
You can, but your computer would stop working because Windows is the operating system, the software that makes it tick and provides a platform for programs, like your web browser, to run on. Without an operating system your laptop is just a box of bits that do not know how to communicate with one another, or you.
Yes and no.
First of all, it's important to remember that whatever your language of choices, in the end the compiled product is in assembly language (or more accurately, machine code). Even interpreters (such as the cpython interpreter) are ultimately translating your scripts into machine code.
But that's probably being overly technical and missing the heart of your question:
"Can I write an operating system in a higher-level language?"
The answers to this are both personal and technical.
First, the personal side: if don't already know how to write an operating system in a mix of assembly language and C then you have absolutely no business trying your hand at OS design.
Often those new to programming have these sorts of questions because they want to do something as cool as writing a new OS without all the learning required to even attempt such a project. They wonder if higher-level languages can be a way to bypass all that messy study.
So if, in your heart-of-hearts, this is what you're after, stop now. Stop, stop, stop. Becoming good at something is hard work. There are no shortcuts. Be ready to roll up your sleeves and get some carpal tunnel syndrome.
That doesn't preclude following a path to eventual OS design! If that's your passion, then start at the top and work your way down. Get books on networking protocols, memory management, threading, etc, tackle each major subsystem and get to know it well. You can't write a new one if you can't use an old one!
Then read books on operating system design and implementation until you dream about process management methodologies.
Just bear in mind, the amount of knowledge necessary (not just of computer operations but of social constructs like APIs) is immense. This is a long journey and a rewarding one. If you truly love this craft like I do, you'll be glad you took the time even if you never actually write an OS.
Now, the technical answer. You're going to need a bootloader, and that must be written in assembly language. After all, your processor doesn't know C#. Past the bootloader phase, you can write your OS code in any language you want and it'll run, assuming your language can compile to machine code binaries (and not bytecode!)
However, even in our current "glut of cycles" computing environment, an OS must be lean and efficient and that's nearly impossible to achieve in a higher level language, even more so in an interpreted language.
Chances are, you'll need to write your own compiler/interpreter of that given language as a core component of your OS. That core compiler would likely allow only a restricted subset of the language (and you'd bootstrap by writing a more robust compiler in the restricted sub-language). Otherwise the performance will be abysmal.
But all of this is horribly complex and a real discussion of the issues requires a depth of knowledge you probably currently lack. But if you have the drive to do so, you can easily change that, and then I'd happily debate approaches all day!
If it makes you feel any better, I do know enough to write an operating system, and still I sit around daydreaming, trying to figure out how much of an OS could I get away with writing in python. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With