C99

Dialect of programming language C

After ANSI C standard was accepted, the language specification stayed the same for a long time. In 1995 Normative Amendment 1 to the standard was published, but it never got much attention. In the late 1990s the standard was revised and published as ISO 9899:1999 in 1999. It is commonly referred to as C99. In March 2000 it was ratified by ANSI.

This standard added the following features to the language:

  • single-line comments //...
  • inline functions
  • variable definition can be anywhere inside the block, not only at the beginning
  • new data types: long long int, extended, _Bool, complex
  • variable length arrays
  • new header files and library functions
  • type-generic math functions (tgmath.h)
  • restrict pointer qualification which allows better code optimization
  • compound literals for structures initialization
  • better support for IEEE floating-point numbers
  • variadic macros (with variable number of parameters)

Most C implementations support this standard, though some of them chose to stop improving and focus on other things instead.

To write code which depends on features which differ in C99 and earlier standards, use __STDC_VERSION__ macro which has value 199901L for this standard.

Examples:

Quadratic equation:

Example for versions gcc 4.2.4

This example requires C99, since it uses complex type introduced in it.

#include <stdio.h>
#include <complex.h>
#include <math.h>

void print(int ind, double complex x) {
    printf("x%d = ", ind);
    if (fabs(cimag(x)) < 1e-6)
        printf("%f\n", creal(x));
    else printf("(%f, %f)\n", creal(x), cimag(x));
}

int main() {
    double A, B, C;
    double D;
    printf("A = ");
    scanf("%lf", &A);
    if (fabs(A)<1E-3) {
        printf("Not a quadratic equation\n");
        return 1;
    }
    printf("B = ");
    scanf("%lf", &B);
    printf("C = ");
    scanf("%lf", &C);

    A *= 2;
    D = B*B-A*C*2.0;
    if (fabs(D)<1E-3)
        printf("x = %f", creal(-B/A));
    else {
        print(1, (-B+csqrt(D))/A);
        print(2, (-B-csqrt(D))/A);
    }
    return 0;
}