160 likes | 653 Views
C Programming Language. Bill Jensen CS 354 May, 3 rd 2007. Catalyst. In late 1960’s Bell Labs left project on Multics, and soon after he and others began working on the Unix Operating System. Ken Thompson wanted a comfortable computing environment of his own design.
E N D
C Programming Language • Bill Jensen • CS 354 • May, 3rd 2007
Catalyst In late 1960’s Bell Labs left project on Multics, and soon after he and others began working on the Unix Operating System. • Ken Thompson wanted a comfortable computing environment of his own design. • B programming language was created, based on languages used when creating Multics; especially BCPL. • Thompson decided Unix needed a system programming language.
Creation • By 1970 Unix had shown promise and Bell Labs acquired the new DEC PDP-11 • By 1971…We all wanted to create interesting software more easily. • B’s problems – 1) Clumsy Character handling 2) Floating point not available on PDP-11 3) Implied overhead with pointers • Alterations to B and a new name, NB.
Creation - continued • NB proved to be insufficient and with further changes was renamed to C. • Many changes around 1972-3, but main was introduction of preprocessor. • Portability developed as I/O Libraries written by Mike Lesk. • 1977 produced changes focused on portability and type safety. • 1978 Brian Kernighan and Dennis Ritchie Published The C Programming Language.
Control - standardization • Portability tests (Interdata 8/32, DEC VAX 11/780) lead to wide spread use during the 1980’s. • Compilers became available on most every machine architecture. • Wide use, including use on commercial and Government projects lead to establishment of X3J11 committee established by ANSI to produce a standardization of C.
Characteristics • An Imperative, Procedural programming language. • Design based on the implementation of computer processors based upon the von Neumann architecture. • Low level access to memory by machine addresses and typed pointers.
Variables, Types & Operators • Variables - Must begin with letter followed by any number and combination of letters and digits. (strings are implemented as char arrays) • Types – char, int (short, long), float, double • shorts, ints – min 16 bits • Long – min 32 bits • Binary Operators: +, -, *, /, % • Logic Operators: >, >=, <, <=, ==, !=, &&, ||, ! (negate) • Bitwise: &, |, ^, <<, >>, - (unary)
Assignment Expressions • Assignment: =, +=, -=, *=, /=, &=, ^=, |=, <<=, >>= • Most associativity is Left to Right • Ex. x = 1 + 2; • Ex. y += 4; (y = y + 4;)
Control Flow • If-Else, Else-If, Switch, Loops, GOTO • Loops – While, For, Do-while • GOTO and Labels – GOTO’s can be useful in error handling in special cases but usually should be avoided • Labels – same form as a variable followed by a colon • “goto statements should be used rarely, it at all” – Kernighan, Ritchie
Pointers and Arrays • Pointers contain addresses of variables. Ex. int x = 10; // var x has value of 10 int *ptr; // ptr points to the address of an int ptr = &x; // ptr now has value of x (10) Arrays can be declared normally and as pointer arrays. Ex. Int array[] // one dimensional int twoDimArray[][] // two dimensional array * Pointer arrays are usually faster but harder to understand.
Structures • Structures – a collection of one or more variables or any type. • Structures are used to help organize complicated data. Ex. Struct account { char *accountHolder; double checkingBalance; double savingsBalance; }
Conclusion • Readability – overall easy to read and intuitive. Pointers can make reading code difficult. • Simplicity – simple design making c easy to learn and apply. • Orthogonality – c is not very restrictive, which allows some creativity and some higher chances of writing bugged code.
Conclusion - continued • Easy to learn basic concepts. • Lack simple implementation of object oriented programming can make class OOP tedious.
Primary Uses • True to its original purpose C is most often used in systems programming. • Operating Systems • Embedded Systems • Intermediate Language for higher-level languages * Java • Computer Game Programming
Bibliography • Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language. New Jersey: Prentice Hall, 1988. • Sebesta, Robert W. Concepts of programming languages. Boston: Pearson, 2006. • Ritchie, Dennis M. The Development of the C Language*. Murray Hill, NJ: . • "C (programming language) • ." wikipedia.org. April, 25th 2007.<http://en.wikipedia.org/wiki/C_programing_language>.