ANSI C – C89 Standard

The C programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs, quickly gained popularity due to its efficiency, portability, and flexibility. However, C variations and extensions by different compiler vendors led to compatibility issues. To address this, the American National Standards Institute (ANSI) formed a committee, X3J11, in 1983 to standardize the language and the standard that came out was ANSI C

In this article, we will explore the different features adopted in ANSI C along with the deprecated features. We will also look at the compiler that provides full support to this standard.

What is ANSI C?

ANSI C also referred to as C89, was the first C Programming Language Standard defined by the American National Standards Institute (ANSI) in 1989. It is officially designated as ANSI X3.159-1989. By standardizing the language for use across compilers and platforms, it represents a major landmark in the evolution of C. ANSI C standard was designed to offer consistent and reliable programming environment that can produce code which works with minimal adjustments on different systems.

The standard was later adopted by the International Organization for Standardization (ISO) as ISO/IEC 9899:1990, often referred to as C90.

Added Features of the ANSI C Standard

The ANSI C Standard adopted the main features of the language along with the features popular at that time from the given compilers. Important features include:

1. Function Prototypes

Function declarations now include the types of their parameters, enabling the compiler to perform type checking.

int add(int a, int b); // Function prototype

2. Standard Library

The C standard library of ANSI included a comprehensive set of functions for input/output operations, string manipulation, memory allocation and more, these standardized set of functions made it easier to write portable code. Libraries are written in the form of header files like:

#include #include

There are total of 24 header files in ANSI Standard

3. New Data Types

ANSI C also introduced the popular and useful data types that were not the part of every compiler version of C. They are

4. Type Qualifiers

The const and volatile qualifiers were added for variables. Prior to the introduction of type qualifiers such as const and volatile, a better regulation was needed for variable modification as well as optimization.

5. Structure Assignment

Direct assignment of structures was allowed. It means that we could assign the structure to another structure just like variables.

Example

struct Point < int x, y; >; struct Point p1 = ; struct Point p2 = p1; // Structure assignment

6. Standardized Predefined Macros

Macros like __FILE__, __LINE__, and __DATE__ were standardized.

7. Formatted Input/Output

Enhanced support for formatted input/output through functions like printf and scanf and more like sscanf, fprintf, etc.

8. Dynamic Memory Allocation

Functions were standardized for dynamic memory management. They included:

int *ptr = (int *)malloc(sizeof(int) * 10);

9. Improved Compatibility and Portability

The standard provided guidelines to ensure consistent behaviour across different platforms and compilers.

Deprecated Features in ANSI C Standard

Because the ANSI C had a number of additions, certain features in earlier versions were deprecated or removed so as to make it uniform and more portable:

1. Implicit Function Declarations

To improve type checking and to avoid errors that might occur and functions that are called without prior declaration or definition are no longer allowed.

2. K&R Function Definitions

Description : Traditional K&R (Kernighan and Ritchie) style function definitions without type information are now obsolete and replaced by new function prototype syntax.

Example (deprecated):

// Deprecated K&R style int add(a, b) int a, b;

Example (new style)

int add(int a, int b) 
return a + b;
>

3. Non-Standard Keywords and Extensions

To enhance its portability and compliance with the standard, non-standard keywords and compiler-specific extensions that were not part of original C language have been abolished.

Compiler Support for ANSI C/C89

Many compilers added support for ANSI C/C89 to ensure compliance with the new standard. Some of the notable compilers that supported ANSI C/C89 include:

  1. GCC (GNU Compiler Collection) : One of the first compilers to adopt the ANSI C standard and continues to support it robustly.
  2. Microsoft C/C++ Compiler : Microsoft Visual C++ (MSVC) added support for ANSI C in its early versions and continues to support ANSI C alongside C++.
  3. Turbo C : Borland’s Turbo C compiler provided support for ANSI C/C89, making it popular among developers in the late 1980s and early 1990s.
  4. Watcom C : Watcom C compiler was known for its excellent ANSI C support and was widely used for developing DOS applications.
  5. IBM XL C/C++ : IBM’s XL C/C++ compiler supported ANSI C, particularly for development on IBM’s AIX operating system.
  6. Clang : The Clang compiler, part of the LLVM project, supports ANSI C/C89, ensuring modern development environments can compile legacy C code.

Conclusion

The introduction of ANSI C/C89 was a critical development in the history of programming languages. By adding new features, standardizing the language, and ensuring wide compiler support, ANSI C/C89 established a solid foundation for writing portable, reliable, and maintainable code. Its influence persists today, as many of the features and conventions introduced in ANSI C continue to shape modern programming practices.