Live data from Hacker News

How to Make a Computer Operating System in C/C++

github.com

11–20 of 88 posts

Re: How to Make a Computer Operating System in C/C++

#12
post #11

It's not C/C++. C/C++ is not a language. The project's goal is to write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?). The code is predominantly C++.

I thought it was a reference to this* when I read the title, but after reading them both I'm not sure there is any connection.

*http://i.imgur.com/fQ1ST8w.jpg

Re: How to Make a Computer Operating System in C/C++

#13
Here [1] you can find another example of writing OS from scratch. Going through chapters progress is made iteratively by making limited changes in each step. This OS is intended to be (RT)OS for embedded computers, but example arch-level is implemented for x86.

[1] https://github.com/l30nard0/Benu

Re: How to Make a Computer Operating System in C/C++

#14
I am a graduate student, currently working on building a x86_64 unix like preemptive kernel from scratch, as part of a course. Most of the OS dev guides and books focus on 32 bit arch and I haven't found a single guide so far that is based on 64 bit arch. Since this this guide seems to be in its inception, I hope someone (hopefully me) will send a pull request for a 64 bit tutorial.

Building an OS has been in my bucket list for long and it has been one heck of an experience so far.

Here are some good step-by-step OS-from-scratch programming guides

http://jamesmolloy.co.uk/tutorial_html/index.html

http://www.osdever.net/bkerndev/Docs/title.htm

http://www.ijack.org.uk/

http://www.brokenthorn.com/Resources/OSDevIndex.html

http://viralpatel.net/taj/operating-system-tutorial.php

and here's a good wiki for reference

http://wiki.osdev.org/Expanded_Main_Page

Re: How to Make a Computer Operating System in C/C++

#15
post #11

It's not C/C++. C/C++ is not a language. The project's goal is to write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?). The code is predominantly C++.

You are correct. Usually I see this in CVs. It usually means that the person is proficient in C++ but knows a little C as well. But C/C++ can be a language. It could be a code written in C++ but looks more like C than C++. Some people e.g. use character arrays instead of string class, avoid STL as much as possible, don't use object-oriented aspects of the language, etc. The end result uses some C++ libraries, compiles on a C++ compiler but resembles C more than anything. I think it would be appropriate to call it C/C++.

Re: How to Make a Computer Operating System in C/C++

#16
This is great. I am just jumping into open source from an academic background. I had assumed that open source was great for directly practical website creating and hosting (back-end, client side etc...) but weaker in terms of learning for OS / compilers. This post and its comments (with linked resources) are making me unsure about this assumption. What do you think?

Re: How to Make a Computer Operating System in C/C++

#17
post #11

It's not C/C++. C/C++ is not a language. The project's goal is to write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?). The code is predominantly C++.

Hm, it doesn't claim it's one language. And it has indeed C code and C++ code...

Re: How to Make a Computer Operating System in C/C++

#18
post #11

It's not C/C++. C/C++ is not a language. The project's goal is to write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?). The code is predominantly C++.

> write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?)

I'm going to use this as an opportunity to champion C++ for systems programming despite the fact that it wasn't really your argument. I feel obligated to do this because I agreed with you for a long time on this but have changed my mind over the past year or two.

The argument against C++ as a systems programming language has always been that it gives you too much freedom to hide complexity, but I've written systems code in both C and C++ professionally and it's been my experience that the extra burden of having to write every damn thing over again in C (or use a relatively poorly tested container library, as compared to something like the STL) is not worth the "obvious performance characteristics."

I'd further contend that in non-trivial software all perf characteristics are non-trivial, so even though a + b might be doing all kinds of crazy things in C++, you're much more likely to run into problems invoking store_value() which might interact with a number of underlying libraries and system calls. At the end of the day you're hopelessly screwed without profiling and the utility perf works just as well on C++ programs as it does on C programs.

Finally, the majority of code in my experience is either slow path or at least not the bottleneck anyway. You can almost always optimize a systems program by making smarter system calls (or hardware invocations), while optimizing CPU is rarely worth it. Even if you're CPU bound, it's likely that it's in doing something like SSL, wherein you're almost definitely wrong to try to jump into a project like OpenSSL with micro-optimizations. With that in mind, why not allow yourself to move faster by creating a std::vector? When you use the proper conventions, it's generally as fast anyway.

Just because people can (and have, a lot) misused C++ and created way too much complexity with it doesn't mean that it's not the preferred language in the hands of someone who knows what they're doing. (And yes, it's much harder to learn how C++ works in a meaningful way to avoid these pitfalls, but if it's your job, learn it anyway).

Re: How to Make a Computer Operating System in C/C++

#19
post #11

It's not C/C++. C/C++ is not a language. The project's goal is to write a very simple UNIX-based operating system in C++ (does anyone else smell a contradiction?). The code is predominantly C++.

You are correct. Usually I see this in CVs. It usually means that the person is proficient in C++ but knows a little C as well. But C/C++ can be a language. It could be a code written in C++ but looks more like C than C++. Some people e.g. use character arrays instead of string class, avoid STL as much as possible, don't use object-oriented aspects of the language, etc. The end result uses some C++ libraries, compile…

I mostly agree with your observation regarding CVs and what seeing this in one tells about the person who wrote it. Although I like to think that most proficient C++ programmers respect the differences between the two languages and prefer to call C++ what it is, and mention C separately if it needs to be mentioned.

I don't think the style of your code should change the name of the language you claim to use. If it doesn't pass through a C compiler, it's not C or "C/anything".

Now it is quite possible to use the subsets of C and C++ to write code that conforms to both language specifications and compiles with a compiler for either language. If some project deliberately does this, I don't have an issue with calling it C/C++ to hilight the fact. This however really is quite rare from what I've seen, even if I can name some projects that do make such code (the Opus audio codec is one example).

C/C++ still isn't a language though, so I would very much prefer to call it C in a case like this.

A different scenario entirely would be a project with parts clearly written in two (or more) different languages, which could happen to be C and C++...

Re: How to Make a Computer Operating System in C/C++

#20
post #14

I am a graduate student, currently working on building a x86_64 unix like preemptive kernel from scratch, as part of a course. Most of the OS dev guides and books focus on 32 bit arch and I haven't found a single guide so far that is based on 64 bit arch. Since this this guide seems to be in its inception, I hope someone (hopefully me) will send a pull request for a 64 bit tutorial. Building an OS has been in my buck…

I think that AMD Developer Guides & Manuals [1] are very good resources for x86_64 System Programming (better than Intel Manuals). They are better explained and focus on x86_64 arch.

[1]: http://developer.amd.com/resources/documentation-articles/de...

Post reply on HN