C and its C and its predecessors predecessors Jukka Jokelainen - - PowerPoint PPT Presentation
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
” ” 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
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
- n UNIX alltho compilers existed for
- n UNIX alltho compilers existed for
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
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
Problem of n queens, Problem of n queens, BCPL BCPL
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.
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
- f addresses of code fragments that
- f 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.)
Example of B Example of B
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-
- riented memory
- riented 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
” ”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
- f the PDP-11 exposed several
- f 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
” ”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
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 adding char char type and rewrote the type and rewrote the 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
Embryonic C Embryonic C
Semantics of arrays
Semantics of arrays remained exactly as in remained exactly as in B and BCPL B and BCPL
Values stored in the
Values stored in the cells bound to array cells bound to array and pointer names and pointer names were the machine were the machine addresses, measured addresses, measured in bytes in bytes
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) int i, j; int i, j; char c, d; char c, d; int iarray[10]; int iarray[10]; int ipointer[]; int ipointer[]; char carray[10]; char carray[10]; char cpointer[]; char cpointer[];
Embryonic C Embryonic C
Structures weren’t only to characterize an
Structures weren’t only to characterize an abstract object but also to describe a abstract object but also to describe a collection of bits that might be read from a collection of bits that might be read from a directory directory
Solution was the crucial jump between
Solution was the crucial jump between typeless BCPL and typed C typeless BCPL and typed C
Pointer is only created when the array
Pointer is only created when the array name is mentioned in an expression this name is mentioned in an expression this way eliminating the materialization of the way eliminating the materialization of the pointer in storage pointer in storage
Because of this, transforming code written
Because of this, transforming code written in B to C was pretty easy in B to C was pretty easy
” ”The solution constituted the crucial The solution constituted the crucial jump in the evolutionary chain jump in the evolutionary chain between typeless BCPL and typed C. between typeless BCPL and typed C. It eliminated the materialization of It eliminated the materialization of the pointer in storage, and instead the pointer in storage, and instead caused the creation of the pointer caused the creation of the pointer when the array name is mentioned in when the array name is mentioned in an expression. The rule, which an expression. The rule, which survives in today's C, is that values survives in today's C, is that values
- f array type are converted, when
- f array type are converted, when
they appear in expressions, into they appear in expressions, into pointers to the first of the objects pointers to the first of the objects making up the array.” making up the array.”
Main differences with C and Main differences with C and its predecessors its predecessors
Is the type system
Is the type system int i, *pi, **ppi; int i, *pi, **ppi; int f(), *f(), (*f)(); int f(), *f(), (*f)(); int *api[10], (*pai)[10]; int *api[10], (*pai)[10];
At this point Ritchie thought the language
At this point Ritchie thought the language could no longer be called nB but deserved could no longer be called nB but deserved a new name a new name
New language was called C, speculation
New language was called C, speculation whether the name represented a whether the name represented a progression through the alphabet or progression through the alphabet or through the letters in BCPL is still open through the letters in BCPL is still open
Neonatal C Neonatal C
Rapid development continued once the new
Rapid development continued once the new language was named (for example the language was named (for example the introduction of the && and || operators.) introduction of the && and || operators.)
This
This was not only made to make
was not only made to make the
the mechanism more explicit but also make the code mechanism more explicit but also make the code more optimizable for the compiler more optimizable for the compiler
Also many other changes were made, but the
Also many other changes were made, but the most important was the introduction of the most important was the introduction of the preprocessor preprocessor
At first it provided only included files and simple
At first it provided only included files and simple string replacements: string replacements: #include and and #define of
- f
parameterless macros parameterless macros
Portability Portability
By early 1973, the essentials of modern C were
By early 1973, the essentials of modern C were complete complete
The language and compiler were so strong Ritchie
The language and compiler were so strong Ritchie and his team were able to rewrite UNIX for and his team were able to rewrite UNIX for PDP-11 with C instead of Assembler PDP-11 with C instead of Assembler
Compiler was first retargeted for Honeywell 635
Compiler was first retargeted for Honeywell 635 and IBM 360/370 and IBM 360/370
Also the prototypes for the modern libraries were
Also the prototypes for the modern libraries were developed developed
Mike Lesk wrote a `portable I/O package' in 1972
Mike Lesk wrote a `portable I/O package' in 1972 that was later reworked to become the C that was later reworked to become the C `standard I/O' routines `standard I/O' routines
1978 Brian Kernighan and Dennis Ritchie wrote
1978 Brian Kernighan and Dennis Ritchie wrote The C Programming Language The C Programming Language aka The White aka The White Bible Bible
Portability 2 Portability 2
1973-1980 the language grew:
1973-1980 the language grew:
type structure gained unsigned, long, union,
type structure gained unsigned, long, union, and enumeration types and enumeration types
structures became nearly first-class objects
structures became nearly first-class objects (lacking only a notation for literals) (lacking only a notation for literals)
1977 Steve Johnson began to work on
1977 Steve Johnson began to work on pcc pcc, , a C compiler intended to be easy to a C compiler intended to be easy to retarget to new machines retarget to new machines
Meanwhile Thompson and Ritchie began to
Meanwhile Thompson and Ritchie began to move the Unix system to the Interdata move the Unix system to the Interdata 8/32 computer 8/32 computer
On this era development of C was largely
On this era development of C was largely focused on considerations of portability focused on considerations of portability
Growth in usage Growth in usage
The success of porting C to Interdata 8/32 soon
The success of porting C to Interdata 8/32 soon led to porting UNIX and C for DEC VAX 11/780 led to porting UNIX and C for DEC VAX 11/780
DEC VAX 11/780 was a lot more popular than
DEC VAX 11/780 was a lot more popular than Interdata machine and user base of C grew Interdata machine and user base of C grew rapidly rapidly
Besides research facilities and universities utitlies
Besides research facilities and universities utitlies like Computer Systems division of AT&T began to like Computer Systems division of AT&T began to use C use C
During the 1980s the use of the C language
During the 1980s the use of the C language spread widely, and compilers became available spread widely, and compilers became available
- n nearly every machine architecture and
- n nearly every machine architecture and
- perating system
- perating system
At the start of the decade, nearly every compiler
At the start of the decade, nearly every compiler was based on Johnson's was based on Johnson's pcc pcc; by 1985 there were ; by 1985 there were many independently-produced compiler products many independently-produced compiler products
Standardization Standardization
1982 need of formal standardization for C
1982 need of formal standardization for C became obvious as the language kept became obvious as the language kept growing and evolving growing and evolving
The best approximation to a standard, the
The best approximation to a standard, the first edition of K&R, no longer described first edition of K&R, no longer described the language in actual use and it also had the language in actual use and it also had no mention of no mention of void d or
- r enum
enum types types
ANSI established the X3J11 committee
ANSI established the X3J11 committee under the direction of CBEMA in the under the direction of CBEMA in the summer of 1983 summer of 1983
ANSI standardized X3J11 at the end of
ANSI standardized X3J11 at the end of 1989, and subsequently this standard was 1989, and subsequently this standard was accepted by ISO as ISO/IEC 9899-1990 accepted by ISO as ISO/IEC 9899-1990
Standardization 2 Standardization 2
X3J11 introduced only one genuinely
X3J11 introduced only one genuinely important change to the language itself, it important change to the language itself, it incorporated the types of formal incorporated the types of formal arguments in the type signature of a arguments in the type signature of a function (borrowed from C++) function (borrowed from C++)
Double sin(); was no longer valid, instead
Double sin(); was no longer valid, instead double sin(double); for more explicit double sin(double); for more explicit argumenting argumenting
The core of C language escaped nearly
The core of C language escaped nearly unscathed from the standardization unscathed from the standardization process process
More important changes took place in the
More important changes took place in the language's surroundings: the preprocessor language's surroundings: the preprocessor and the library and the library
Preprocessor performs macro substitution,
Preprocessor performs macro substitution,
X3J11 & NCEG X3J11 & NCEG
The current activity of the X3J11
The current activity of the X3J11 committee is confined to issuing committee is confined to issuing interpretations on the existing standard interpretations on the existing standard
An informal group originally convened by
An informal group originally convened by Rex Jaeschke as NCEG (Numerical C Rex Jaeschke as NCEG (Numerical C Extensions Group) has been officially Extensions Group) has been officially accepted as subgroup X3J11.1, and they accepted as subgroup X3J11.1, and they continue to consider extensions to C continue to consider extensions to C
Many of these possible extensions are
Many of these possible extensions are intended to make the language more intended to make the language more suitable for numerical use: for example, suitable for numerical use: for example, multi-dimensional arrays whose bounds multi-dimensional arrays whose bounds are dynamically determined are dynamically determined
Evolution of C after Evolution of C after ANSI-C ANSI-C
ANSI-C (or C89) is supported by current C
ANSI-C (or C89) is supported by current C compilers, and most C code being written compilers, and most C code being written nowadays is based on it. nowadays is based on it.
The C programming language uses
The C programming language uses libraries as its primary method of libraries as its primary method of extension extension
Following ISO standard ,C99, was
Following ISO standard ,C99, was published to correct some details and to published to correct some details and to add more extensive support for add more extensive support for international character sets international character sets
In 2007, work began in anticipation of
In 2007, work began in anticipation of another revision of the C standard, another revision of the C standard,
Objective C Objective C
” ”Objective-C
Objective-C is a is a reflective reflective, , object-oriented
- bject-oriented
programming programming language language, which adds , which adds Smalltalk Smalltalk-
- style
style messaging messaging to the to the C C programming programming language language. . Today it is used primarily on Apple's Today it is used primarily on Apple's Mac OS X Mac OS X and and iPhone iPhone OS OS: two environments based on, : two environments based on, although not compliant with, the although not compliant with, the OpenStep OpenStep standard. standard.[1] [1] Objective-C is the primary language Objective-C is the primary language used for Apple's used for Apple's Cocoa Cocoa API API, and it was originally , and it was originally used as the main language on used as the main language on NeXT NeXT's 's NeXTSTEP NeXTSTEP
- OS. Generic Objective-C programs
- OS. Generic Objective-C programs
which do not
which do not make use of these libraries can also be make use of these libraries can also be compiled for any system supported by compiled for any system supported by gcc gcc, , which includes an Objective-C compiler.” which includes an Objective-C compiler.”
References References
HOPL I & II HOPL I & II
http://www.engin.umd.umich.edu/CIS/course.des/cis400/c/c.html http://www.engin.umd.umich.edu/CIS/course.des/cis400/c/c.html
http://www.levenez.com/lang/ http://www.levenez.com/lang/
http://cm.bell-labs.com/cm/cs/who/dmr/chist.html http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
http://www.open-std.org/jtc1/sc22/wg14/ http://www.open-std.org/jtc1/sc22/wg14/