: This is my first post to this news group.I want to know how
:compiler writers write the library functions like printf() , scanf()
:etc.Are they using Assembly Language,Machine Language ? Or are they
:written in C ?
That depends on the compiler writers and the machines and upon
the need for efficiency and upon the features provided by the
underlying operating system.
: Even though they write in Assembly Language , each
rocessor has its own instruction set.So how the same program is
:running in all type of machines ?
Oh, you'll find that in practice identical programs do not always
produce identical outputs on different operating systems.
Programmers are [more or less] human and make mistakes or have
different interpretations.
Generally speaking:
- there is a lot that can be written in pure C provided that
you have a memory allocator, a facility to open and close
files, and way to read and write streams of bytes for
devices and blocks of bytes for files.
- compiler writers have underlying operating system facilities
to draw upon, and those facilities often already include
sufficient OS interfaces to make writing the libraries
much easier
- the language of implimentation is not important. What is
important is that the compiler writer provides a way of
translating C code into local code that calls upon the
operating system as needed to provide basic functions.
- a lot of the basic OS functions are very similar amongst
unix systems, making it easier to "port" the libraries to new
machines that already have a unix-like OS.
- once a minimal set of interfaces are in place, one has
enough expressive power to be able to write library functions
in terms of those minimal interfaces
- you should think more about this question:
How does anyone write a compiler for a machine that does not
already have a compiler to write the new compiler in?