Channels ▼


The State of C

The ANSI Standard

For many years, the definition of C was the reference manual in the first edition of The C Programming Language. In 1983, ANSI established a committee to provide a modern, comprehensive definition of C. The result, the ANSI standard, or ANSI C, is expected to be approved late in 1988. Modern compilers already support most of the features of the standard.

The language has changed relatively little since 1978; one of the goals of the standard was to make sure that most existing programs would remain valid, or, failing that, that compilers could produce warnings of new behavior.

Basically, the most important change is a new syntax for declaring and defining functions. A function declaration can now include a description of the function's arguments; the definition syntax changes to match. This extra information makes it much easier for compilers to detect errors that are caused by mismatched arguments; in our experience, it's a very useful addition.

To illustrate, consider this typical fragment of C as it would once have been written:

int n;
double x, sqrt( }; 
x = sqrt(n};

The sqrt function expects an argument of type double, but n is an int. This error is not detected, and the results are guaranteed to be nonsense. With the new function prototype syntax from ANSI C, you would write the fragment this way:

int n;
double x, sqrt(double);
x = sqrt(n);

Here the compiler has been informed about the type that sqrt expects, so it generates code to convert the integer n to floating point. If you inadvertently wrote an expression that couldn't be converted to double, such as x = sqrt (&n); , the compiler would catch the error.

The syntax of function definitions changes to match; formal parameters are listed between parentheses after the function name. Thus, the function bitcount would become:

bitcount(unsigned int n)

There are also other small-scale language changes. Structure assignment, enumerations, and the void data type, all of which had been widely available, are now officially part of the language. You can initialize automatic structures and arrays, and you can do floating-point computations in single-precision; this may lead to more efficient computation on smaller machines.

The properties of arithmetic conversions are spelled out more carefully. There are now hexadecimal constants and escape sequences as well as the octal ones. The C preprocessor, which does textual macro substitution, is much more elaborate; it gives substantially more control over the macrogeneration process. Most of these changes will have only minor effects on your programming.

A second significant contribution of the standard is the definition of a library to accompany C. It specifies functions for accessing the operating system (e.g., to read and write files), formatted input and output (scanf and printf), memory allocation (malloc), string manipulation (e.g., strcmp), mathematical computations (e.g., sin and lag), and the like.

A collection of standard header files to be included with user-written programs provides uniform access to declarations of functions and data types. Programs that use this library to interact with a host system are assured of compatible behavior. Most of the library is closely modeled on the Unix system's "standard I/O library," and similar routines are widely available on other systems as well. Again, you won't see much change.

Because most computers directly support the data types and control structures that C provides, the run-time library required to implement self-contained programs is tiny. The standard library functions are only called explicitly, so you can avoid them if you don't need them. Most of them can be written in C and, except for the operating-system details they conceal, are themselves portable.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.