C programming is developed and standardized by ANSI and ISO and is famous for its powerful, flexible, and elegant language. Because of its suitability for both systems based as well as application-based programming it has become an industry standard, general purpose language today. The standardization committee which is working on C are trying to check each element of the language critically and decided that a change or enhancement is necessary to continue its legacy and popularity. So, new features were included with a new version - C99. It is recognized as one of the advanced topics of C. In this chapter, you will learn about the features that are available in C99 standard but not in its previous version.
What is C99?
The C99, previously known as the C9X, is an informal name for ISO/IEC 9899:1999 of C programming standard. It is the enhanced and newer version of C90 with added features for the language and the standard library and hence makes use of a better implementation of the available computer hardware such as the IEEE arithmetic and compiler technology.
Important Features of C99
The C99 standard introduces several new language features. These new features include:
- Some features are like extensions to C90 offered by GNU compiler such as macros with a variable number of arguments.
- C99 allows the use of sophisticated numbers and designated initializers.
- Restricted pointers are also added in C99.
- There are some new keywords and identifiers.
- New comment techniques
- Inline functions
- Variable length array
- Flexible array members
- New header files were included
- Addition of Compound Literals
History of C99
As the official standard for C language was produced by ANSI (American National Standard Institute) in the year 1989, and then became an international standard in the year 1990, the specification of the C language remains relatively static for some time, with the evolving C++. The standard underwent further revision in the late 1990s, leading to the publication of ISO/IEC 9899:1999 in the year 1999, which was adopted as an ANSI standard in May 2000. So the C language defined by that version of the standard is commonly referred to as "C99".
The C99 standard incorporates new enhancements and included advanced features that are desirable for any modern computer language. Some of the features are borrowed from C++ while others are a modification of few constructs.
New C99 Keywords
ANSI C has defined 32 keywords in C. C99 has added five more keywords to that old group of keywords. Addition of these new keywords is perhaps the most significant feature of C99. The new 5 keywords are:
_Bool
_Bool: as the name suggests is of type integer which is used to declare Boolean type variables i.e. it can store only zeros (0s) and ones (1s). This is a new data type of C introduced by C99.
_Complex
_Complex: It is used to declare complex floating type variables to store mathematical complex numbers. This is a new data type that is included in C99. They are declared as:
Syntax:
float _Complex variable_name; double _Complex variable_name; Example: float _Complex z = l + 2*J;
or it can also be declared as:
Syntax:
float complex z = l + 2*J; z = l/z;
if the header file <complex.h> is included at the beginning of the program.
_Imaginary
_Imaginary: It is used to declare imaginary floating type variables store mathematical imaginary numbers. This is also a new data type included by C99. It is declared like that of _Complex -
Syntax:
double _Imaginary variable_name; float _Imaginary variable_name;
inline
inline: The objective of the inline specifier is to supply a hint for the compiler to perform optimizations, such as function inlining, that require the definition of a function to be visible at the call site. The compilers can ignore the presence or absence of the inline specifier for the purpose of optimization.
Example:
static int g;
inline void k(void)
{
static int s = 1;
int x = g;
/*The above line is an error because the non-static inline function is accessing the static variable*/
}
restrict
restrict: C99 has introduced the "restrict" keyword as a type qualifier that can be used only for pointers. A pointer when qualified with the keyword 'restricted' is referred to as a restricted pointer. Restricted pointers are declared as follows:
Example:
int *restrict pt; void *restrict ptr1;
When a pointer is declared as restricted, it becomes the only means to access the object it points to.
Declaration of variables
It is legal to declare variables it at any point of the program within the curly braces of main() function.
Example:
#include<stdio.h>
#include <complex.h>
main()
{
int g;
g = 600;
. . .
. . .
int k; // Legal in C99
k = 200;
. . .
}
Variable Array length
In ANSI C, array dimension must have to be declared. But C99 permits declaration of array dimensions using integer variables or any valid integer expressions. This is called Variable length array.
This is how the variable length arrays are declared:
Example:
#include<stdio.h>
main()
{
int x, y;
scanf("%d %d", &x, &y);
float matrix [x][y]; /*Variable Length array*/
. . .
. . .
}
Comment Technique
C99 allows to put comment using a double front slash (//) which is done in C++, and the C compiler does not show any error which was not possible in ANSI C.