Page 1 of 1
a little weird question
Posted: Wed Apr 02, 2014 9:53 pm
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!
Re: a little weird question
Posted: Wed Apr 02, 2014 10:01 pm
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. :-)
Re: a little weird question
Posted: Wed Apr 02, 2014 11:18 pm
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
Re: a little weird question
Posted: Wed Apr 02, 2014 11:37 pm
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
Re: a little weird question
Posted: Thu Apr 03, 2014 12:09 am
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?
Re: a little weird question
Posted: Thu Apr 03, 2014 12:44 am
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