How to write a "Hello World" in C?

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.
Locked
NewOSdever
Posts: 2
Joined: Tue Dec 13, 2016 6:04 am
Libera.chat IRC: nikitka555

How to write a "Hello World" in C?

Post by NewOSdever »

Hello World! My name is Nikita. i'm new. Help me please,how to write a "Hello World" in C
I am not catnikita255, do not confuse me and him.
jmziprick
Posts: 1
Joined: Thu Jul 31, 2014 3:43 pm

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

Post by jmziprick »

http://wiki.osdev.org/Bare_Bones

You should read through the wiki, you can learn a lot from it.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

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

Post 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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

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

Post 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.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

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

Post 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...
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

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

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
Locked