Header Files

T

thushianthan15

Hi ,
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 ?
Even though they write in Assembly Language , each
processor has its own instruction set.So how the same program is
running in all type of machines ?
Please explain.
 
B

Ben Pfaff

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 ?

It could be any of those or any combination of them. Most
commonly these days they are written mostly in C with small
pieces of assembly language here and there as needed.
 
W

Walter Roberson

: 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
:processor 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?
 
M

Martin Ambuhl

Hi ,
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 ?

They could be written in anything. Implementation details are not
specified by the standard. When I was writing first compilers, we used
assembly language exclusively (MACRO-10, to be exact). When I moved to
MULTICS, the initial tiny bootstrapping PL/1 compiler was assembler
(GE-645), with subsequent compilers written mostly in the language
already implemented. The mix of assembler/higher-level languages is a
trade-off between ease of implementation and efficiency. A good
optimizing compiler can be used for most things to compile itself for
another platform.
Even though they write in Assembly Language , each
processor has its own instruction set.So how the same program is
running in all type of machines ?

By having different code generation stages for different architectures
and platforms.
 
T

thushianthan15

Martin said:
They could be written in anything. Implementation details are not
specified by the standard. When I was writing first compilers, we used
assembly language exclusively (MACRO-10, to be exact). When I moved to
MULTICS, the initial tiny bootstrapping PL/1 compiler was assembler
(GE-645), with subsequent compilers written mostly in the language
already implemented. The mix of assembler/higher-level languages is a
trade-off between ease of implementation and efficiency. A good
optimizing compiler can be used for most things to compile itself for
another platform.


By having different code generation stages for different architectures
and platforms.

I thank to every one who explained this topic to me.
 
T

thvv

Martin said:
They could be written in anything. Implementation details are not
specified by the standard. When I was writing first compilers, we used
assembly language exclusively (MACRO-10, to be exact). When I moved to
MULTICS, the initial tiny bootstrapping PL/1 compiler was assembler
(GE-645), with subsequent compilers written mostly in the language
already implemented.

A small correction. The bootstrap PL/I compiler on the GE-645 Multics
machine, in the late 1960s, was called EPL. It was written in
McClure's
TMG language, not assembly language, by a team at Bell Labs led by
Doug McIlroy and Bob Morris. See http://www.multicians.org/pl1.html
The succeeding generations of PL/I compilers on Multics were written
in the earlier versions of the language.

Although Mr. Abuhl is right that library functions could be written
in any language, language runtimes are often implemented in assembly
language. The Multics PL/I compilers after EPL generated threaded
code, so that most language builtin functions were called by a fast
call to the segment pl1_operators_ which was part of every address
space. It was written in assembly language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,421
Latest member
StacyTaver

Latest Threads

Top