In this article we will study about various C standards that specified after its development in Bell Labs. We’ll study from ANSI C also called as C89, C90, C95, C99, C11 and the latest C18. This article will cover standards specifications, technical details, features etc.
Note: If you are Newbie I recommend you to study C standards at Last of completing C programming.
In the previous article we studied C language introduction if you are new to programming we recommend you to study it first. Read Here.
Let’s get back to C standards.
K&R C Standards
In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language book, known as “K&R”, served as an informal specification of the language for many years. This version of C is often described as K&R C.
K&R introduced several language features:
- Standard I/O library.
- long
int
data type. - unsigned
int
data type. - Compound assignment operators such as
=op
i.e.=-
changed toop=
i.e.-=
to remove the semantic ambiguity formed by constructs such asi=-10,
which is interpreted asi =- 10
(decrement i by 10) instead ofi = -10
( i equals to -10). - K&R 1st edition did *not* have function prototypes. The declaration of add would have to be
int add();
or justadd();
, and its definition would have to start
int add(a, b)
int a, b;
{
In early versions of C, functions that do not have return type has “INT” as default return type. Even in today’s compilers “int” presumed if not declared in prototype and definition with warning.
For Example:
#include <stdio.h>
add(int a,int b);
int main()
{
int a = 0;
printf("Add = %d\n",add(2,3));
return 0;
}
add(int a,int b)
{
return (a+b);
}
Output:
Add = 5
Warnings: (Compiled in Codeblock)
||=== Build: Debug in eresa (compiler: GNU GCC Compiler) ===|
main.c|2|warning: data definition has no type or storage class|
main.c|2|warning: type defaults to 'int' in declaration of 'add' [-Wimplicit-int]|
main.c|9|warning: return type defaults to 'int'[-Wreturn-type]||
The int type specifiers which are commented out could be omitted in K&R C, but are required in later C standards.After the publication of K&R C, several features added to the language, supported by compilers from other vendors. These included:
void
functions (i.e., functions with no return value).- Functions returning
struct
or union types (rather than pointers). - Assignment for
struct
data types and Enumerated types.
Though the fact is not even the Unix compilers precisely implemented the K&R specification, this led to the necessity of C standardization.
C89 Standard
The C language previously did not have any elementary functions, such as I/O operations. Over time, user communities of C language shared ideas of implementing those functions.
These ideas eventually incorporated into the definition of the standardized C language in 1989. These are now called the C standard libraries.
In 1970s the C language became widely popular, with many universities and organizations begins to create their own variations of the language. At start of 1980s compatibility problems between the various C implementations became apparent.
In 1983, American National Standards Institute (ANSI) formed a committee to establish a standard specification for C. The standard completed in 1989 ratified as ANSI X3.159-1989 “Programming Language C” also known as “ANSI C“. Later it is labelled “C89” to distinguish it from C99.
C89 is compatible in current C compilers, and C code written today mostly based on it.
C90 Standard
The same C89 standard was ratified by the International Organization for Standardization as ISO/IEC 9899:1990, with only formatting changes which referred to as C90. Therefore, the “C89” and “C90” refer the same language.
C95 Standard
After 1990, C Standards remained static without change for several years. In 1995, ISO published a Normative amendment 1 for C90 named ISO/IEC 9899/AMD1:1995 (which known as “C95”) to correct some details and to add more extensive support for international character sets.
- Enhanced multi-byte and wide character supported by the standard library.
- Adding Headers like
<iso646.h>, <wchar.h>, and <wctype.h>
as well as multi-byte I/O. - Addition of digraphs to the language.
- Specification of standard macros for the operators, e.g.
and, for, &&.
- Specification of the standard macro
__STDC_VERSION__.
C99 Standard
In 1990, International Organization for Standardization published standard ISO/IEC 9899:1999 with some addition known as C99.
Added Features:
- Built-in data types:
long long, _Bool, _Complex, and _Imaginary.
- Added new features including static array indices, designated initializers, compound literals, variable-length arrays, flexible array members, variadic macros, restrict keyword and one-line comments beginning with //.
- Library headers, including
<tgmath.h>, <inttypes.h>,<stdbool.h>,<complex.h>, <fenv.h>, <stdint.h>, .
- Several C++ features such as inline functions, mixing declarations and code, and universal character names in identifiers.
- C90 is stricter in some ways particularly in a declaration that lacks a type specifier no longer has
int
implicitly assumed. - A macro
__STDC_VERSION__
is defined with a value199901L .
C11 Standard
After C99, C remain untouched for more than a decade. In 2011, ISO published a standard ISO/IEC 9899:2011 on December 8, 2011 commonly known as “C11”.
A standard macro __STDC_VERSION__
is defined with value to201112L
. Some features of C11 are supported in GCC compilers from version 4.6.
Changes in C11:
-
_Alignof
operator,_Alignas
specifier,aligned_alloc
function,<stdalign.h>
header file - The
_Noreturn
function specifier and the<stdnoreturn.h>
header file - Type-generic expressions using the
_Generic keyword
. - Removal of the gets function, deprecated in the previous C language standard revision.
- Structure and union, useful when unions and structures are nested, e.g. in
struct E { int Ext; union { float x; int i; };
};.
C18 Standard
Latest standard version for the C programming language was published in June 2018 termed as”C18“. It replaced C11 (standard ISO/IEC 9899:2011).
Support was scheduled for GCC 8 and LLVM Clang 6.0
Changes from C11
- C18 addressed flaws in C11 without introducing new language features.
- The
__STDC_VERSION__
macro changed to the value201710L
.
Study more about C standards Click Here
Some direct links to free PDF files of the C89/C90, C99 and C11 standards are listed below: