Microsoft Store
 

C programming language


 

The C programming language is a standardized imperative computer programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications. It is also commonly used in computer science education, despite not being designed for novices.

History

Early developments

The initial development of C occurred at AT&T Bell Labs between 1969 and 1973; according to Ritchie, the most creative period occurred in 1972. It was named "C" because many of its features were derived from an earlier language called "B".

Related Topics:
AT&T - Bell Labs - 1969 - 1973 - 1972 - B

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Accounts differ regarding the origins of the name "B": Ken Thompson credits the BCPL programming language, but he had also created a language called Bon in honor of his wife Bonnie.

Related Topics:
Ken Thompson - BCPL - Bon

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

There are many legends as to the origin of C and its related operating system, Unix, including:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • The development of C was the result of the programmers' desire to play Space Travel. They had been playing it on their company's mainframe, but being underpowered and having to support about 100 users, Thompson and Ritchie found they didn't have sufficient control over the spaceship to avoid collisions with the wandering space rocks. Thus, they decided to port the game to an idle PDP-7 in the office. But it didn't have an operating system (OS), so they set about writing one. Eventually they decided to port the operating system to the office's PDP-11, but this was since all the code was in assembly language. They decided to use a higher-level portable language so the OS could be ported easily from one computer to another. They looked at using B, but it lacked functionality to take advantage of some of the PDP-11's advanced features. So they set about creating the new language, C.
  • The justification for obtaining the original computer that was used to develop Unix was to create a system to automate the filing of patents. The original version of Unix was developed in assembly language. Later, the C language was developed in order to rewrite the operating system.
  • By 1973, the C language had become powerful enough that most of the UNIX kernel, originally written in PDP-11/20 assembly language, was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly, earlier instances being the Multics system (written in PL/I), TRIPOS (written in BCPL), and MCP (Master Control Program) for Burroughs B5000 written in ALGOL in 1961.

    Related Topics:
    1973 - UNIX - Kernel - PDP-11/20 - Multics - PL/I - TRIPOS - Master Control Program - B5000 - ALGOL

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

K&R C

In 1978, Ritchie and Brian Kernighan published the first edition of The C Programming Language. This book, known to C programmers as "K&R", served for many years as an informal specification of the language. The version of C that it describes is commonly referred to as "K&R C." (The second edition of the book covers the later ANSI C standard, described below.)

Related Topics:
1978 - Brian Kernighan - The C Programming Language - Specification - ANSI C

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

K&R introduced the following features to the language:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • struct data types
  • long int data type
  • unsigned int data type
  • The =+ operator was changed to +=, and so forth (=+ was confusing the C compiler's lexical analyzer; for example, i =+ 10 compared with i = +10).
  • K&R C is often considered the most basic part of the language that is necessary for a C compiler to support. For many years, even after the introduction of ANSI C, it was considered the "lowest common denominator" that C programmers stuck to when maximum portability was desired, since not all compilers were updated to fully support ANSI C, and reasonably well-written K&R C code is also legal ANSI C.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    In these early versions of C, only functions that returned a non-integer value needed to be declared before use. A function used without any previous declaration was assumed to return an integer.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Example call requiring previous declaration:

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    :

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    long int SomeFunction();

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    int CallingFunction()

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    long int ret;

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    ret = SomeFunction();

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    }

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Example call not requiring previous declaration:

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    :

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    int SomeOtherFunction()

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    return 0;

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    }

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    int CallingFunction()

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    int ret;

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    ret = SomeOtherFunction();

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    }

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Since the K&R prototype did not include any information about function arguments, function parameter type checks were not performed, although some compilers would issue a warning message if a function was called with the wrong number of arguments.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    In the years following the publication of K&R C, several "unofficial" features were added to the language, supported by compilers from AT&T and some other vendors. These included:

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • void functions and void * data type
  • functions returning struct or union types
  • struct field names in a separate name space for each struct type
  • assignment for struct data types
  • const qualifier to make an object read-only
  • a standard library incorporating most of the functionality implemented by various vendors
  • enumerations
  • the single-precision float type

ANSI C and ISO C

During the late 1970s, C began to replace BASIC as the leading microcomputer programming language. During the 1980s, it was adopted for use with the IBM PC, and its popularity began to increase significantly.

Related Topics:
1970s - BASIC - Microcomputer - 1980s - IBM PC

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

At the same time, Bjarne Stroustrup and others at Bell Labs began work on adding object-oriented programming language constructs to C.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

The language they produced, called C++, is now the most common application programming language on the Microsoft Windows operating system; C remains more popular in the Unix world. Another language developed around that time is Objective-C which also adds object oriented programming to C. While, now, not as popular as C++, it is used to develop Mac OS X's Cocoa applications.

Related Topics:
C++ - Microsoft Windows - Objective-C - Mac OS X - Cocoa

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

In 1983, the American National Standards Institute (ANSI) formed a committee, X3J11, to establish a standard specification of C. After a long and arduous process, the standard was completed in 1989 and ratified as ANSI X3.159-1989 "Programming Language C". This version of the language is often referred to as ANSI C.

Related Topics:
1983 - American National Standards Institute - 1989 - ANSI C

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

In 1990, the ANSI C standard (with a few minor modifications) was adopted by the International Organization for Standardization (ISO) as ISO/IEC 9899:1990.

Related Topics:
1990 - International Organization for Standardization

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

One of the aims of the ANSI C standardization process was to produce a superset of K&R C, incorporating many of the unofficial features subsequently introduced.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

However, the standards committee also included several new features, such as function prototypes (borrowed from C++), and a more capable preprocessor.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

ANSI C is now supported by almost all the widely used compilers. Most of the C code being written nowadays is based on ANSI C. Any program written only in standard C is guaranteed to perform correctly on any platform with a conforming C implementation. However, many programs have been written that will only compile on a certain platform, or with a certain compiler, due to (i) the use of non-standard libraries, such as for graphical displays, and (ii) some compilers' not adhering to the ANSI C standard, or its successor, in their default mode, or (iii) reliance on the exact size of certain datatypes as well as on the endianness of the platform.

Related Topics:
Platform - Graphical displays - Endian

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

You can use the __STDC__ macro to split your code into ANSI and K&R sections.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • if __STDC__
  • extern int getopt(int,char * const *,const char *);

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • else
  • extern int getopt();

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • endif
  • ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    Some suggest using "#if __STDC__", like above, over "#ifdef __STDC__" because some compilers set __STDC__ to zero to indicate non-ANSI compliance.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

C99

After the ANSI standardization process, the C language specification remained relatively static for some time, whereas C++ continued to evolve. (Normative Amendment 1 created a new version of the C language in 1995, but this version is rarely acknowledged.) However, the standard underwent revision in the late 1990s, leading to the publication of ISO 9899:1999 in 1999.

Related Topics:
C++ - 1995 - 1990s - 1999

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

This standard is commonly referred to as "C99". It was adopted as an ANSI standard in March 2000.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

The new features in C99 include:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • inline functions
  • variables can be declared anywhere (as in C++), rather than only after another declaration or the start of a compound statement
  • several new data types, including long long int (to reduce the pain of the looming 32-bit to 64-bit transition), an explicit boolean data type, and a complex type representing complex numbers
  • variable-length arrays
  • support for one-line comments beginning with //, like in BCPL or C++, and which many C compilers have previously supported as an extension
  • several new library functions, such as snprintf()
  • several new header files, such as stdint.h
  • Interest in supporting the new C99 features appears to be mixed. Whereas GCC and several other compilers now support most of the new features of C99, the compilers maintained by Microsoft and Borland do not, and these two companies do not seem to be interested in adding such support.

    Related Topics:
    GCC - Microsoft - Borland

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~