Page 1 of 1

How to write a "Hello World" in C?

Posted: Tue Dec 13, 2016 12:30 pm
by NewOSdever
Hello World! My name is Nikita. i'm new. Help me please,how to write a "Hello World" in C

Re: How to write a "Hello World" in C?

Posted: Tue Dec 13, 2016 1:15 pm
by jmziprick
http://wiki.osdev.org/Bare_Bones

You should read through the wiki, you can learn a lot from it.

Re: How to write a "Hello World" in C?

Posted: Tue Dec 13, 2016 1:40 pm
by Schol-R-LEA
By "Hello, World!", I am assuming you mean a HW boot loader or OS stub, rather than the general question of how to use C. If it is the latter, then I would recommend moving this inquiry to the General Programming sub-forum.

As jmziprick stated, you should review the Bare Bones example in the Wiki. However, I would go further and give you a number of links to read (if you haven't done so already), just to get you up to speed on what you will need to know when working in the OS dev space:

Getting Started
How To Ask Questions
FAQ

Required Knowledge
Beginner Mistakes (the "deadlines" section in particular)
What order should I make things in
Code Management

How kernel, compiler, and C library work together
Using Programming Languages other than C

Real Mode, especially the section on memory addressing, and Segmentation
Memory Map, Detecting Memory and A20 Line
BIOS, and Boot Sequence
Interrupts
Bootloader and Rolling Your Own Bootloader
FAT and SFS

While this is a lot of reading, it simply reflects the due diligence that any OS-devver needs to go through in order to get anywhere. OS development, even as a simple project, is not amenable to the Stack Overflow cut-and-paste model of software development; you really need to understand a fair amount of the concepts and principles before writing any code, and the examples given in tutorials and forum posts generally are exactly that. Copying an existing code snippet without at least a basic idea of what it is doing simply won't do. While learning itself is an iterative process - you learn one thing, try it out, see what worked and what didn't, read some more, etc. - in this case a basic foundation is needed at the start. Without a solid understanding of at least some of the core ideas before starting, you simply can't get very far in OS dev.


Hopefully, this won't scare you off; it isn't nearly as bad as it sounds. It just takes a lot of patience and a bit of effort, a little at a time.

Re: How to write a "Hello World" in C?

Posted: Wed Dec 14, 2016 5:50 am
by osdever
Info that you provided is useful for newbies, but not for him. I know him personally and he won't really understand the wiki. I think that it was a mistake to providing him with link to OSDev :(

Nope, I don't want to offend you, Nikita. I just say that you shall learn C in userspace first.

Re: How to write a "Hello World" in C?

Posted: Wed Dec 14, 2016 9:37 am
by SpyderTL
I think I might just start with learning Assembly before I touched C.

A "Hello World" OS in Assembly is just a few lines of code.

A "Hello World" program in C requires you to understand C, the compiler, the linker, and probably GRUB as well.

Just a thought...

Re: How to write a "Hello World" in C?

Posted: Thu Dec 15, 2016 1:46 am
by Kevin
Wrong approach, he should start with neither an OS in assembly nor an OS in C. Someone who has never programmed, needs to start in userspace. And for doing that, assembly requires understanding a lot of low-level details like registers, memory addresses, system calls, etc. while C is comparatively straightforward for simple tasks.