473,480 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Header Files

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.

Nov 14 '05 #1
5 1385
"th************@hotmail.com" <th************@hotmail.com> writes:
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.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
In article <11**********************@f14g2000cwb.googlegroups .com>,
th************@hotmail.com <th************@hotmail.com> wrote:
: 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?
--
Warning: potentially contains traces of nuts.
Nov 14 '05 #3
th************@hotmail.com wrote:
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.
Nov 14 '05 #4

Martin Ambuhl wrote:
th************@hotmail.com wrote:
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.


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

Nov 14 '05 #5

Martin Ambuhl wrote:
th************@hotmail.com wrote:
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.


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.

Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2201
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... ...
21
2565
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds...
16
12495
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
11
2727
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
3
3071
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
11
5537
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
18
2720
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module...
8
2747
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
9
4028
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
36
3779
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.