When someone says "I Want a programming language in which I need only say what I wish done," give him a lolipop.*


what is C? The simple answer-a widely used programming language developed in the early 1970s at Bell Laboratories-conveys little of C's special flavor. Before we become immersed in the details of the language, let's take a look at where C came from, what it was designed for, and how it has changed over the years (Sec-tion 1.1). We'll also discuss C's strengths and weaknesses and see how to get the most out of the language (Section 1.2).


1.1 History of C

Let's take a quick look at C's history. from its origins, to its coming of age as a standardized language, to its influence on recent languages. 


Origins

C is a by-product of the UNIX operationg system, which was developed at Bell Lab-oratories by Ken Thopson, Dennis Richie, and others. Thompson single-hand-eldly wrote the original version of UNIX, which ran on the DEC PDP-7 computer, an early minicomputer with only 8K words of main memory (this was 1969, after all!).

Like other operating systems of the time, UNIX was written in assembly lan-guage. Programs written in assembly language are usually painful to debug and hard to enhance; UNIX was no exception. Thompson decided that a higher-level language was needed for the further development of UNIX, so he designed a small language named B. Thompson based B on BCPL, a systems programming language developed in the mid-1960s. BCPL, in turn, traces its ancestry to Algol 60, one of the earliest (and most influential) programming languages.

Ritchie soon joined the UNIX project and began programming in B. In 1970. Bell Labs acquired a PDP-11 for the UNIX in B. By 1971. it became apparent that B was not well-suited to the PDP-11, so Richie began to develop an extended version of B. Hel called his language NB ("New B") at first, and then, as it began to diverge more from B, he changed the name to C. The language was sta-ble enough by 1973 that UNIX could be rewritten in C. The switch to C provided an important benefit: portability. By writing C compilers for other computers at Bell Labs, the team could get UNIX running on those machines as well.


Standardization

C continued to evolve during the 1970s, especially between 1977 and 1979. It was during this period that the first book on C appeared. The C Programming Lan-guage, written by Brian Kernighan and Dennis Ritchie and published in 1978. quickly became the bible of C programmers. In the absence of an officail standard for C, this book-known as K&R or the "White Book" to aficionados-served as a de facto standard.


During the 1970s. there were relatively few C programmers, and most of the, were UNIX users. By the 1980s, however, C had expanded beyond the narrow con-fines of the UNIX world. C compilers became available on a variety of machines running under different operating systems. In particular, C began to establish itself on the fast-growing IBM PC platform. 


With C's increasing popularity came problems. Programmers who wrote new C compilers relied on K&R as a reference. Unfortunately, K&R was fuzzy about some language features, so compilers often treated these features differently. Also, K&R failed to make a clear distinction between which features belonged to C and which were part of UNIX. To make matters worse, C continued to change after K&R was published, with new features being added and a few older features removed. The need for a thorough, precise, and up-to-date description of the lan-guage soon became apparent. Without such a standard, numerous dialects would have arisem, threatening the portability of C programs, one of the language's major strengths.


The development of a U.S. standard for C began in 1983 under the auspices of the American National Standards Institute (ANSI). After many revisions, the stan-dard was completed in 1988 and formally approved in December 1989 as ANSI standard X3.159-1989. In 1990, it was approved by the International Organization for Standardization (ISO) as international standard ISO/IEC 9899:1990. This ver-sion of the language is usually referred to as C89 or C90, to distinguish it from the original cersion of C, often called K&R C. Appendix C summarizes the major dif-ferences between C89 and K&R C.


The language underwent a few changes in 1995 (described in a document known as Amendment 1). More significant changes occurred with the publication of a new standard, 1). More significant changes occurred with the publication of a new standard, ISO/IEC 9899:1999, in 1999. The language described in this standard is commonly known as C99. The terms "ANSI C," "ANSI/ISO C," and "ISO C" -Once used to describe C89-are now ambiguous, thanks to the existence of two standards.


Because C99 isn't yet universal, and because of the need to maintain millions(if not billions) of lines of code written in older versions of C, I'll use a special icon(shown in the left margin) to mark discussions of features that were added in C99. A compiler that doesn't recognize these features isn't "C99-compiant." If histroy is any guide, it will be some years before all C compilers are C99-compliant, if they ever are. Appendix B lists the major differences between C99 and C89.


C-Based Languages

c ha had a huge influence on modern-day programming languages, many of which borrow heavily from it. Of the many C-based languages, several are espe-cially prominent:

C++ includes all the features of C, but adds classes and other features to sup-port object-oriented programming.

Java is base on C++ and therefore inherits many C features.

C# is a mor recent language derived from C++ and Java.

Perl was originally a fairly simple scripting language; over time it has grown and adopted many of the features of C.


Considering the popularity of these newer languages, it's logical to ask whether it's worth the trouble to learn C. I think it is, for several reasons. First, learning C can give you greater insight into the features of C++, Java, C#, Perl, and the other C-based languages. Programmers who learn one of these languages first often fail to master basic features that were inherited from C. Second, there are a lot of older C programs around; you may find yourself needing to read and main-tain this code. Third, C is still widely used for developing new software, especially in situations where memory or processing power is limited or where the simplicity of C is desired.


If you haven't already used one of the newer C-based languages, you'll find that this book is excellent preparation for learning these languages. It emphasizes data abstraction, information hiding, and other principles that play a large role in object-oriented programming. C++ includes all the features of C, so you'll be able to use everything you learn from this book if you later tackle C++. Many of the features of C can be found in the other C-based languages as well.


1.2 Strengths and Weaknesses of C


Like any other programming language, C has strengths and weaknesses. Both stem from the language's original use (writing operating systems and other systems software) and its underlying philosophby:


C is a low-level language. To serve as a suitable language for systems pro-gramming, C provides access to machine-level concepts (bytes and addresses, for example) that other programming languages try to hide. C also provides operations that correspond closely to a computer's built-in instructions. so that programs can be fast. Since application programs rely on it for input/output , storage management, and numerous other services, an operating system can't afford to be slow.

C is a small language. C provides a more limited set of features than many languages. (The reference manual in the second edition of K&R covers the entire language in 49 pages.) To keep the number of features small, C relies heavily on a "library" of standard functions. (A "function" is similar to what other programming languages might call a "procedure." "subroutine." or "method.")


C is a permissive language. C assumes that you know what you're doing, so it allows you a wider degree of latitude than many languages. Moreover, C doesn't mandate the detailed error-checking in other languages.

Strengths

C's strengths help explain why the language has become so popular:

Efficiency. Efficiency has been one of C's advantages from the beginning. Because C was intended for applications where assembly language had tradi-tionally been used, it was crucial that C programs could run quickly and in limited amounts of memory. 


portability. Although program portability wasn't primary goal of C, it has turned out to be one of the language's When a program must run on computers ranging from PCs to supercomputers, it is often written in C. One reason for the portability of C programs is that-thanks to C's early associa-tion into incompatible dialects. Another is that C compilers are small and easily written, which has helped make them widely available. Finally, C itself has features that support portability (although there's nothing to prevent pro-grammers from writing nonportable programs).


power. C's large collection of data types and operators help make it a power-ful language. In C, it's often possible to accomplish quite a bit with just a few lines of code.


Flexibility. Although C was originally designed for systems programming, it has no inherent restrictions that limit it no this arena. C is now used for appli-cations of all kinds, from embedded systems to commercial data processing. Moreover, C imposes very few restrictions on the use of its features; opera-tions that would be illegal in other languages are often permitted in C. For example, C allows a character to be added to an integer value (or, for that mat-ter, a floating-point number). This flexibility can make programming easier, although it may allow some bugs to slip through.

Standard library. One of C's great strengths is its standard library, which con-tains hundreds of functions for 


Weaknesses



+ Recent posts