0% found this document useful (0 votes)
21 views

brainrot1

Uploaded by

quib2410694
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

brainrot1

Uploaded by

quib2410694
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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 (Section 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 operating system, which was developed at Bell Laboratories by Ken Thompson,
Dennis Ritchie, and others. Thompson single-handedly 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 language. 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 project. Once B was up and running on
the PDP-11, Thompson rewrote a portion of UNIX in B. By 1971, it became
apparent that B was not well-suited to the PDP-11, so Ritchie began to develop an
extended version of B. He 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 stable 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 Language, written by Brian Kernighan and
Dennis Ritchie and published in 1978,
quickly became the bible of C programmers. In the absence of an official 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 them
were UNIX users. By the 1980s, however, C had expanded beyond the narrow confines 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 language soon became apparent.
Without such a standard, numerous dialects would
have arisen, 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 standard 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 version of the language is usually
referred to as C89 or C90, to distinguish it from the original version of C, often called K&R C. Appendix C
summarizes the major differences 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, 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-compliant.” If history
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 has had a huge influence on modern-day programming languages, many of
which borrow heavily from it. Of the many C-based languages, several are especially prominent:
■ C++ includes all the features of C, but adds classes and other features to support object-oriented programming.

■ Java is based on C++ and therefore inherits many C features.

■ C# is a more 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 maintain 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 philosophy:
■ C is a low-level language. To serve as a suitable language for systems programming, 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 found 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 traditionally been used, it was crucial that C
programs could run quickly and in
limited amounts of memory.
■ Portability. Although program portability wasn’t a primary goal of C, it has

turned out to be one of the language’s strengths. 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 association with UNIX and the later ANSI/ISO
standards—the language hasn’t splintered 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 programmers from writing nonportable
programs).
■ Power. C’s large collection of data types and operators help make it a powerful language. In C, it’s often possible

to accomplish quite a bit with just a few


lines of code.

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 philosophy:
■ C is a low-level language. To serve as a suitable language for systems programming, 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 found 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 traditionally been used, it was crucial that C
programs could run quickly and in
limited amounts of memory.
■ Portability. Although program portability wasn’t a primary goal of C, it has

turned out to be one of the language’s strengths. 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 association with UNIX and the later ANSI/ISO
standards—the language hasn’t splintered 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 programmers from writing nonportable
programs).
■ Power. C’s large collection of data types and operators help make it a powerful language. In C, it’s often possible

to accomplish quite a bit with just a few


lines of code.

You might also like