The differences between C99 and C89

In sum, C originated in the year 1969 but the language was stable enough by 1973

Standardization

furthermore, In 1978, in the absence of an official standard for C, it was known as K&R

The development of a u.s standard for C began in 1983 known as ANSI then after many revisions, the standard was completed in 1988 and formally approved as an ANSI standard and it also got approved by ISO by 1990

So, the revision of this version of the language is usually referred to as C89 OR C90

Thereafter, as the language underwent a few changes, as a result, a new standard was introduced in 1999 known as C99

Variables, keywords, and comments

Variables

In C89 variable declarations must come first before you write a statement in the block or a function With C99 we can mix the declaration of a variable with the statements

comments

/* this is a comment in C89 */

Whereas, C99 introduced a new kind of comment (two slashes //)

// this is a comment in C99

Keywords

Presently, C89 has 32 standard keywords

But, in C99 five new keywords were added such as

KeywordC89C99
Inline
restrict
_Bool
_Complex
_Imaginary

Data types in C99

  • Provide a Boolean type name _Bool an unsigned integer for which we can assign 0 or 1
  • Allows two additional integer types long long int and unsigned long long int
  • Provide a <stdbool.h> header file which defines the bool data type as a true and false
  • C99 has a provision for writing floating constants in hexadecimal such a constant begins with ox or OX

For loop in C99

In C99 The first argument in the for loop can be replaced by a declaration

for(int i=1;i<=10;i++)

With this feature, we don’t need to declare the variable i before  the for loop

Input/output

C99 changes to Printf conversion specification

  • Additional length modifiers.  Such as hh, ll, j, z, and t the length modifiers hh and ll provide additional  length options  j allows greater width integers, and z and t make it easier to write values of type size_t and ptrdiff_t
  • Additional conversion specifiers. Such as F, a
  • Have the ability to read infinity and NaN
  • Support the wide character. Fprintf can write wide characters, thus, the %lc conversion specification is used to write a single wide character and the %ls is used for a string of wide characters
  • In C89 the conversion specification such as %le, %E, %lf, %lg, and %lG are undefined. But they are legal in C99
  • snprintf function  C99 added the snprintf function o the <stdio.h> header file

Arrays

With C89 you need to initialize the array by element by an element such as

int Array[14]={0,0,0,50,0,0,0,0,0,88,0,0,4,0};

As can be seen, element 3 of the array is 50, element 9 is 88, and element 12 is 4 but the other values are just zero’s

For instance, for a large array initializing with this technique will be tedious and error-prone

Even if we have 100 zeros between two nonzero elements then it will not be effective to write all the zeros

C99 can solve this problem by designating initializers, at this time, we can write the above array as

int Array[14]={[3]=50,[9]=88,[12]=4};

Thats it! Short and simple right?

Furthermore, you can write the elements of the array in any order

int Array[14]={[9]=88,[12]=4,[3]=50,[9]=88};

Even more, you can mix both C89 [element by element] technique and the newer C99 designated technique

int Array[14]={0,0,0,[3]=50,0,0,0,0,0,[9]=88,0,0,[12]=4,0};

Preprocessor

C99 supports some new predefined macros such as

C99 can accept empty macro arguments but it should have the same number of commas as in the pre-processor directive

Functions

  • In C99 we don’t have a default return type of a function but, when it comes to C89 , if you didn’t declare the function return type then, in that case, the return of a function  will be assumed as an int
  • C99 allows variable length array parameters in a function declaration such as
int sum_array(int b[], int n)
{
......
}

Where the sum_array is a function name

  • At the same time, C99 also allows us to use keyword static in the declaration of array parameters
int sum_array(int b[static 4], int n)
{
........
{

At the same time, C99 also allows us to use keyword static in the declaration of array parameters

Here, static  4 means that the length will be at least 4

  • We can use compound literals with C99
    • It is legal to use the return type of a main() function as a void, float, or any other datatype with the C99 version of C
    #include <stdio.h>
    #include <stdlib.h>
    float main()
    {
        printf("Hello world!\n");
        //return 0;
    }
    • It is illegal to use the return type of a main() function as a void, float, or any other datatype with the C89 version of C
    • It is legal in C99 to write the main() function without returning a value because the standard states that the main() function will automatically return 0
    return 0;

    C99 provides additional support for mathematics

    The following header files provide additional support for mathematics in C99

    • <stdint.h>
    • <inttypes.h>
    • <complex.h>
    • <tgmath.h>
    • <fenv.h>

    Mohammed Anees

    Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

    Leave a Reply

    Your email address will not be published.