Header Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thushianthan15@hotmail.com

    #1

    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,Machin e 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.

  • Ben Pfaff

    #2
    Re: Header Files

    "thushianthan15 @hotmail.com" <thushianthan15 @hotmail.com> writes:
    [color=blue]
    > 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,Machin e Language ? Or are they
    > written in C ?[/color]

    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[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
    \n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
    );while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
    );}return 0;}

    Comment

    • Walter Roberson

      #3
      Re: Header Files

      In article <1110178495.237 955.257410@f14g 2000cwb.googleg roups.com>,
      thushianthan15@ hotmail.com <thushianthan15 @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,Machin e 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.

      Comment

      • Martin Ambuhl

        #4
        Re: Header Files

        thushianthan15@ hotmail.com wrote:[color=blue]
        > 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,Machin e Language ? Or are they
        > written in C ?[/color]

        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.
        [color=blue]
        > 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 ?[/color]

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

        Comment

        • thushianthan15@hotmail.com

          #5
          Re: Header Files


          Martin Ambuhl wrote:[color=blue]
          > thushianthan15@ hotmail.com wrote:[color=green]
          > > Hi ,
          > > This is my first post to this news group.I want to know how
          > > compiler writers write the library functions like printf() ,[/color][/color]
          scanf()[color=blue][color=green]
          > > etc.Are they using Assembly Language,Machin e Language ? Or are they
          > > written in C ?[/color]
          >
          > They could be written in anything. Implementation details are not
          > specified by the standard. When I was writing first compilers, we[/color]
          used[color=blue]
          > assembly language exclusively (MACRO-10, to be exact). When I moved[/color]
          to[color=blue]
          > 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[/color]
          a[color=blue]
          > trade-off between ease of implementation and efficiency. A good
          > optimizing compiler can be used for most things to compile itself for[/color]
          [color=blue]
          > another platform.
          >[color=green]
          > > 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 ?[/color]
          >
          > By having different code generation stages for different[/color]
          architectures[color=blue]
          > and platforms.[/color]

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

          Comment

          • thvv

            #6
            Re: Header Files


            Martin Ambuhl wrote:[color=blue]
            > thushianthan15@ hotmail.com wrote:[color=green]
            > > Hi ,
            > > This is my first post to this news group.I want to know how
            > > compiler writers write the library functions like printf() ,[/color][/color]
            scanf()[color=blue][color=green]
            > > etc.Are they using Assembly Language,Machin e Language ? Or are they
            > > written in C ?[/color]
            >
            > They could be written in anything. Implementation details are not
            > specified by the standard. When I was writing first compilers, we[/color]
            used[color=blue]
            > assembly language exclusively (MACRO-10, to be exact). When I moved[/color]
            to[color=blue]
            > MULTICS, the initial tiny bootstrapping PL/1 compiler was assembler
            > (GE-645), with subsequent compilers written mostly in the language
            > already implemented.[/color]

            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.

            Comment

            Working...