a little weird question

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.
Post Reply
dashllh
Posts: 3
Joined: Wed Apr 02, 2014 9:33 pm

a little weird question

Post by dashllh »

Sorry,I know this question may be a little weird,but I feel it is important.
That is--can I program in C without any OS? If the answer is "Yes",how can a C compiler be "Installed" at this kind of situation?
thanx in advance! :D
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: a little weird question

Post by sortie »

You forgot to read the forum rules!

This is not a weird question, as much as an obviously already answered question. You certainly can write C programs that work without any operating system. That is what a kernel written in C is. That's what this website is about. As for how, you can spot the link

The OSDev.org Wiki - Got a question? Search this first!

above. This should be sufficient answer when combined with the forum rules. :-)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: a little weird question

Post by Brendan »

Hi,
dashllh wrote:That is--can I program in C without any OS? If the answer is "Yes",how can a C compiler be "Installed" at this kind of situation?
A C compiler requires certain things to run (e.g. access to files, memory, etc). Those things are normally provided by an OS. In theory, it may be possible to port a C compiler to run on "bare metal", but to do that you'd end up implementing things like file systems, disk device drivers, etc, and would end up with a limited OS that happens to compile things.

Also, you can't program with a compiler alone. You'd need some way to read compiler errors (virtual terminal, shell?), a way to edit source files, a linker, misc. utilities (e.g. to create/delete directories), etc.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
dashllh
Posts: 3
Joined: Wed Apr 02, 2014 9:33 pm

Re: a little weird question

Post by dashllh »

sortie wrote:You forgot to read the forum rules!

This is not a weird question, as much as an obviously already answered question. You certainly can write C programs that work without any operating system. That is what a kernel written in C is. That's what this website is about. As for how, you can spot the link

The OSDev.org Wiki - Got a question? Search this first!

above. This should be sufficient answer when combined with the forum rules. :-)
Thank you very much for reply ,sortie.
I will follow the rules:D
dashllh
Posts: 3
Joined: Wed Apr 02, 2014 9:33 pm

Re: a little weird question

Post by dashllh »

Brendan wrote:Hi,
dashllh wrote:That is--can I program in C without any OS? If the answer is "Yes",how can a C compiler be "Installed" at this kind of situation?
A C compiler requires certain things to run (e.g. access to files, memory, etc). Those things are normally provided by an OS. In theory, it may be possible to port a C compiler to run on "bare metal", but to do that you'd end up implementing things like file systems, disk device drivers, etc, and would end up with a limited OS that happens to compile things.

Also, you can't program with a compiler alone. You'd need some way to read compiler errors (virtual terminal, shell?), a way to edit source files, a linker, misc. utilities (e.g. to create/delete directories), etc.


Cheers,

Brendan
Thank you very much for providing me useful detailed knowledge :)
I guess what you mean is -- a compiler have to work together with an OS(at least a limited one),am i right?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: a little weird question

Post by Brendan »

Hi,
dashllh wrote:Thank you very much for providing me useful detailed knowledge :)
I guess what you mean is -- a compiler have to work together with an OS(at least a limited one),am i right?
That depends on how you define "compiler" and "OS".

For example; I could imagine a bootable hex editor thing that takes input (hex characters) from the keyboard and "compiles the input" by converting it to integers and "generates output" by storing the integers in memory. In my opinion, a tool like this might be considered a compiler (if you define "compiler" loosely) but wouldn't meet the minimum requirements needed to call itself an OS; and would therefore be a compiler without an OS.

Your original question was specifically about a C compiler though. A C compiler must comply with (at least one version of) the standards that define C; which implies that it must (e.g.) support the "#include" pre-processor directive. This alone means that something resembling file IO (and the ability to store source code to be used later) must exist.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply