c and its c and its predecessors predecessors
play

C and its C and its predecessors predecessors Jukka Jokelainen - PowerPoint PPT Presentation

C and its C and its predecessors predecessors Jukka Jokelainen Jukka Jokelainen 17.11.2009 17.11.2009 The C programming language was The C programming language was devised in the early 1970s as a devised in the early 1970s as a


  1. C and its C and its predecessors predecessors Jukka Jokelainen Jukka Jokelainen 17.11.2009 17.11.2009

  2. ” The C programming language was The C programming language was ” devised in the early 1970s as a devised in the early 1970s as a system implementation language for system implementation language for the nascent Unix operating system. the nascent Unix operating system. Derived from the typeless language Derived from the typeless language BCPL, it evolved a type structure; BCPL, it evolved a type structure; created on a tiny machine as a tool created on a tiny machine as a tool to improve a meager programming to improve a meager programming environment, it has become one of environment, it has become one of the dominant languages of today. ” - ” - the dominant languages of today. D. Ritchie D. Ritchie

  3. History Overview History Overview  Algol 60->CPL->BCPL->B->C Algol 60->CPL->BCPL->B->C  C was developed 1969-1973 in C was developed 1969-1973 in parallel with early versions of the parallel with early versions of the UNIX, mostly by Dennis Ritchie UNIX, mostly by Dennis Ritchie  Most creative period was during year Most creative period was during year 1972 1972  Other important period was Other important period was 1977-1979 because of portable UNIX 1977-1979 because of portable UNIX systems were introduced systems were introduced  Until early 1980s C was used mainly Until early 1980s C was used mainly on UNIX alltho compilers existed for on UNIX alltho compilers existed for

  4. History: the setting History: the setting  Late 1960s Multics project Late 1960s Multics project  Project involved MIT, GE and Bell Project involved MIT, GE and Bell Labs Labs  1969 Multics shut down by Bell Labs 1969 Multics shut down by Bell Labs management management  GE-645 Multics machine gave an idea GE-645 Multics machine gave an idea to a team led by Ken Thompson to to a team led by Ken Thompson to investigate alternative way of investigate alternative way of approach approach  1969 Thompson developed original 1969 Thompson developed original UNIX on PDP-7 machine, he wrote it UNIX on PDP-7 machine, he wrote it

  5. BCPL BCPL  Martin Richards, Cambridge, 1967 Martin Richards, Cambridge, 1967  Typeless Typeless  Everything a machine word (n-bit integer) Everything a machine word (n-bit integer)  Pointers (addresses) and integers identical Pointers (addresses) and integers identical  Memory: undifferentiated array of words Memory: undifferentiated array of words  Natural model for word-addressed Natural model for word-addressed machines machines  No dynamically-sized automatic objects No dynamically-sized automatic objects  Strings awkward: Routines expand and Strings awkward: Routines expand and pack bytes to/from word arrays pack bytes to/from word arrays  Originally intended for writing compilers Originally intended for writing compilers for other languages for other languages

  6. Problem of n queens, Problem of n queens, BCPL BCPL

  7. Early days of UNIX Early days of UNIX  PDP-7 was a very cramped hardware with PDP-7 was a very cramped hardware with 8K 18-bit words memory 8K 18-bit words memory  1969 Doug McIlroy created first higher- 1969 Doug McIlroy created first higher- level language for PDP-7 UNIX: an level language for PDP-7 UNIX: an implementation of TMG implementation of TMG  TMG was a programming language used TMG was a programming language used for writing compilers for Multics (PL/I for for writing compilers for Multics (PL/I for example) example)  Thompson did not want TMG reproduced Thompson did not want TMG reproduced and thought UNIX needed a system and thought UNIX needed a system programming language programming language  After trying out Fortran he quickly decided After trying out Fortran he quickly decided to create a language of his own, B. to create a language of his own, B.

  8. What is B? What is B?  B can be thought of as C without types B can be thought of as C without types  More accurately B is BCPL squeezed in 8K More accurately B is BCPL squeezed in 8K bytes of memory and filtered through bytes of memory and filtered through Thompson’s brain Thompson’s brain  Compiled to threaded words instead of Compiled to threaded words instead of machine language machine language  Compiler's output consists of a sequence Compiler's output consists of a sequence of addresses of code fragments that of addresses of code fragments that perform the elementary operations perform the elementary operations  Operations typically act on a simple stack Operations typically act on a simple stack machine machine  Clever inventions to reduce size of Clever inventions to reduce size of programs (x =+ y, insted of x = x+y etc.) programs (x =+ y, insted of x = x+y etc.)

  9. Example of B Example of B

  10. DEC PDP-11 DEC PDP-11  24K memory, 12K used for OS 24K memory, 12K used for OS  Because of success of UNIX project, Because of success of UNIX project, Thompsons development team got this Thompsons development team got this new hardware new hardware  1971 more and more users began to use 1971 more and more users began to use this new hardware for their studies at Bell this new hardware for their studies at Bell Labs Labs  PDP-11 exposed several inadequacies of PDP-11 exposed several inadequacies of B's semantic model because it had byte- B's semantic model because it had byte- oriented memory oriented memory  PDP-11 had 16-bit memory and it was PDP-11 had 16-bit memory and it was about to get support for floating-point about to get support for floating-point arithmetic – old way to use float type with arithmetic – old way to use float type with

  11. ”The machines on which we first used The machines on which we first used ” BCPL and then B were word- BCPL and then B were word- addressed, and these languages' addressed, and these languages' single data type, the `cell,' single data type, the `cell,' comfortably equated with the comfortably equated with the hardware machine word. The advent hardware machine word. The advent of the PDP-11 exposed several of the PDP-11 exposed several inadequacies of B's semantic model. inadequacies of B's semantic model. First, its character-handling First, its character-handling mechanisms, inherited with few mechanisms, inherited with few changes from BCPL, were clumsy: changes from BCPL, were clumsy: using library procedures to spread using library procedures to spread packed strings into individual cells packed strings into individual cells and then repack, or to access and and then repack, or to access and

  12. ” ”B and BCPL model implied overhead B and BCPL model implied overhead in dealing with pointers: the in dealing with pointers: the language rules, by defining a pointer language rules, by defining a pointer as an index in an array of words, as an index in an array of words, forced pointers to be represented as forced pointers to be represented as word indices. Each pointer reference word indices. Each pointer reference generated a run-time scale generated a run-time scale conversion from the pointer to the conversion from the pointer to the byte address expected by the byte address expected by the hardware.” hardware.” - D. Ritchie D. Ritchie -

  13. Transition from B to C Transition from B to C  1971 Dennis Ritchie began to expand B by 1971 Dennis Ritchie began to expand B by adding char char type and rewrote the type and rewrote the adding compiler to produce machine code for compiler to produce machine code for PDP-11 PDP-11  Goal was to create compiler so efficient Goal was to create compiler so efficient the new language could compete with the new language could compete with assembler in efficiency assembler in efficiency  Language was first called ’new-B’ or nB Language was first called ’new-B’ or nB  Life of nB was very short before the Life of nB was very short before the language evolved to C language evolved to C  nB actually existed such a short time that nB actually existed such a short time that there wasn’t even a full description ever there wasn’t even a full description ever written written

  14. Embryonic C Embryonic C  Semantics of arrays Semantics of arrays int i, j; int i, j; remained exactly as in remained exactly as in char c, d; char c, d; B and BCPL B and BCPL  Values stored in the Values stored in the int iarray[10]; int iarray[10]; cells bound to array cells bound to array int ipointer[]; int ipointer[]; and pointer names and pointer names were the machine were the machine addresses, measured addresses, measured char carray[10]; char carray[10]; in bytes in bytes char cpointer[]; char cpointer[];  Problems with B came Problems with B came back when extending back when extending the type notation the type notation (structured record (structured record type) type)

Recommend


More recommend