C99

Last updated

Cover of the C99 standards document ISO-IEC-9899-1999-cover.png
Cover of the C99 standards document

C99 (previously known as C9X) is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard. [1] It extends the previous version (C90) with new features for the language and the standard library, and helps implementations make better use of available computer hardware, such as IEEE 754-1985 floating-point arithmetic, and compiler technology. [2] The C11 version of the C programming language standard, published in 2011, updates C99.

Contents

History

After ANSI produced the official standard for the C programming language in 1989, which became an international standard in 1990, the C language specification remained relatively static for some time, while C++ continued to evolve, largely during its own standardization effort. Normative Amendment 1 created a new standard for C in 1995, but only to correct some details of the 1989 standard and to add more extensive support for international character sets. The standard underwent further revision in the late 1990s, leading to the publication of ISO/IEC 9899:1999 in 1999, which was adopted as an ANSI standard in May 2000. The language defined by that version of the standard is commonly referred to as "C99". The international C standard is maintained by the working group ISO/IEC JTC1/SC22/WG14.

Design

1999 ISO C Concepts.png

C99 is, for the most part, backward compatible with C89, but it is stricter in some ways. [3]

In particular, a declaration that lacks a type specifier no longer has int implicitly assumed. The C standards committee decided that it was of more value for compilers to diagnose inadvertent omission of the type specifier than to silently process legacy code that relied on implicit int. In practice, compilers are likely to display a warning, then assume int and continue translating the program.

C99 introduced several new features, many of which had already been implemented as extensions in several compilers: [4]

Parts of the C99 standard are included in the current version of the C++ standard, including integer types, headers, and library functions. Variable-length arrays are not among these included parts because C++'s Standard Template Library already includes similar functionality.

IEEE 754 floating-point support

A major feature of C99 is its numerics support, and in particular its support for access to the features of IEEE 754-1985 (also known as IEC 60559) floating-point hardware present in the vast majority of modern processors (defined in "Annex F IEC 60559 floating-point arithmetic"). Platforms without IEEE 754 hardware can also implement it in software. [2]

On platforms with IEEE 754 floating point:

FLT_EVAL_METHOD == 2 tends to limit the risk of rounding errors affecting numerically unstable expressions (see IEEE 754 design rationale) and is the designed default method for x87 hardware, but yields unintuitive behavior for the unwary user; [9] FLT_EVAL_METHOD == 1 was the default evaluation method originally used in K&R C, which promoted all floats to double in expressions; and FLT_EVAL_METHOD == 0 is also commonly used and specifies a strict "evaluate to type" of the operands. (For gcc, FLT_EVAL_METHOD == 2 is the default on 32 bit x86, and FLT_EVAL_METHOD == 0 is the default on 64 bit x86-64, but FLT_EVAL_METHOD == 2 can be specified on x86-64 with option -mfpmath=387.) Before C99, compilers could round intermediate results inconsistently, especially when using x87 floating-point hardware, leading to compiler-specific behaviour; [10] such inconsistencies are not permitted in compilers conforming to C99 (annex F).

Example

The following annotated example C99 code for computing a continued fraction function demonstrates the main features:

#include<stdio.h>#include<math.h>#include<float.h>#include<fenv.h>#include<tgmath.h>#include<stdbool.h>#include<assert.h>doublecompute_fn(doublez)// [1]{#pragma STDC FENV_ACCESS ON  // [2]assert(FLT_EVAL_METHOD==2);// [3]if(isnan(z))// [4]puts("z is not a number");if(isinf(z))puts("z is infinite");longdoubler=7.0-3.0/(z-2.0-1.0/(z-7.0+10.0/(z-2.0-2.0/(z-3.0))));// [5, 6]feclearexcept(FE_DIVBYZERO);// [7]boolraised=fetestexcept(FE_OVERFLOW);// [8]if(raised)puts("Unanticipated overflow.");returnr;}intmain(void){#ifndef __STDC_IEC_559__puts("Warning: __STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.");// [9]#endif#pragma STDC FENV_ACCESS ON#ifdef TEST_NUMERIC_STABILITY_UPfesetround(FE_UPWARD);// [10]#elif TEST_NUMERIC_STABILITY_DOWNfesetround(FE_DOWNWARD);#endifprintf("%.7g\n",compute_fn(3.0));printf("%.7g\n",compute_fn(NAN));return0;}

Footnotes:

  1. Compile with: gcc-std=c99-mfpmath=387-otest_c99_fptest_c99_fp.c-lm
  2. As the IEEE 754 status flags are manipulated in this function, this #pragma is needed to avoid the compiler incorrectly rearranging such tests when optimising. (Pragmas are usually implementation-defined, but those prefixed with STDC are defined in the C standard.)
  3. C99 defines a limited number of expression evaluation methods: the current compilation mode can be checked to ensure it meets the assumptions the code was written under.
  4. The special values such as NaN and positive or negative infinity can be tested and set.
  5. long double is defined as IEEE 754 double extended or quad precision if available. Using higher precision than required for intermediate computations can minimize round-off error [11] (the typedef double_t can be used for code that is portable under all FLT_EVAL_METHODs).
  6. The main function to be evaluated. Although it appears that some arguments to this continued fraction, e.g., 3.0, would lead to a divide-by-zero error, in fact the function is well-defined at 3.0 and division by 0 will simply return a +infinity that will then correctly lead to a finite result: IEEE 754 is defined not to trap on such exceptions by default and is designed so that they can very often be ignored, as in this case. (If FLT_EVAL_METHOD is defined as 2 then all internal computations including constants will be performed in long double precision; if FLT_EVAL_METHOD is defined as 0 then additional care is need to ensure this, including possibly additional casts and explicit specification of constants as long double.)
  7. As the raised divide-by-zero flag is not an error in this case, it can simply be dismissed to clear the flag for use by later code.
  8. In some cases, other exceptions may be regarded as an error, such as overflow (although it can in fact be shown that this cannot occur in this case).
  9. __STDC_IEC_559__ is to be defined only if "Annex F IEC 60559 floating-point arithmetic" is fully implemented by the compiler and the C library (users should be aware that this macro is sometimes defined while it should not be).
  10. The default rounding mode is round to nearest (with the even rounding rule in the halfway cases) for IEEE 754, but explicitly setting the rounding mode toward + and - infinity (by defining TEST_NUMERIC_STABILITY_UP etc. in this example, when debugging) can be used to diagnose numerical instability. [12] This method can be used even if compute_fn() is part of a separately compiled binary library. But depending on the function, numerical instabilities cannot always be detected.

Version detection

A standard macro __STDC_VERSION__ is defined with value 199901L to indicate that C99 support is available. As with the __STDC__ macro for C90, __STDC_VERSION__ can be used to write code that will compile differently for C90 and C99 compilers, as in this example that ensures that inline is available in either case (by replacing it with static in C90 to avoid linker errors).

#if __STDC_VERSION__ >= 199901L/* "inline" is a keyword */#else# define inline static#endif

Implementations

Most C compilers provide support for at least some of the features introduced in C99.

Historically, Microsoft has been slow to implement new C features in their Visual C++ tools, instead focusing mainly on supporting developments in the C++ standards. [13] However, with the introduction of Visual C++ 2013 Microsoft implemented a limited subset of C99, which was expanded in Visual C++ 2015. [14]

Future work

Since ratification of the 1999 C standard, the standards working group prepared technical reports specifying improved support for embedded processing, additional character data types (Unicode support), and library functions with improved bounds checking. Work continues on technical reports addressing decimal floating point, additional mathematical special functions, and additional dynamic memory allocation functions. The C and C++ standards committees have been collaborating on specifications for threaded programming.

The next revision of the C standard, C11, was ratified in 2011. [41] The C standards committee adopted guidelines that limited the adoption of new features that have not been tested by existing implementations. Much effort went into developing a memory model, in order to clarify sequence points and to support threaded programming.

See also

Related Research Articles

ANSI C, ISO C, and Standard C are successive standards for the C programming language published by the American National Standards Institute (ANSI) and ISO/IEC JTC 1/SC 22/WG 14 of the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC). Historically, the names referred specifically to the original and best-supported version of the standard. Software developers writing in C are encouraged to conform to the standards, as doing so helps portability between compilers.

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

<span class="mw-page-title-main">Floating-point arithmetic</span> Computer approximation for real numbers

In computing, floating-point arithmetic (FP) is arithmetic that represents subsets of real numbers using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. Numbers of this form are called floating-point numbers. For example, 12.345 is a floating-point number in base ten with five digits of precision:

In computing, NaN, standing for Not a Number, is a particular value of a numeric data type which is undefined as a number, such as the result of 0/0. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinities.

Double-precision floating-point format is a floating-point number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.

The C preprocessor is the macro preprocessor for several computer programming languages, such as C, Objective-C, C++, and a variety of Fortran languages. The preprocessor provides inclusion of header files, macro expansions, conditional compilation, and line control.

The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard. Starting from the original ANSI C standard, it was developed at the same time as the C library POSIX specification, which is a superset of it. Since ANSI C was adopted by the International Organization for Standardization, the C standard library is also called the ISO C library.

In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply-add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that performs the operation is known as a multiplier–accumulator ; the operation itself is also often called a MAC or a MAD operation. The MAC operation modifies an accumulator a:

The IEEE Standard for Floating-Point Arithmetic is a technical standard for floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found in the diverse floating-point implementations that made them difficult to use reliably and portably. Many hardware floating-point units use the IEEE 754 standard.

A variadic macro is a feature of some computer programming languages, especially the C preprocessor, whereby a macro may be declared to accept a varying number of arguments.

<span class="mw-page-title-main">GNU MPFR</span> C library for arbitrary-precision floating-point arithmetic

The GNU Multiple Precision Floating-Point Reliable Library is a GNU portable C library for arbitrary-precision binary floating-point computation with correct rounding, based on GNU Multi-Precision Library.

<span class="mw-page-title-main">C data types</span> Data types supported by the C programming language

In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.

In C and related programming languages, long double refers to a floating-point data type that is often more precise than double precision though the language standard only requires it to be at least as precise as double. As with C's other floating-point types, it may not necessarily map to an IEEE format.

C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating-point numbers in one manner or another. Different C standards provide different, albeit backwards-compatible, sets of functions. Most of these functions are also available in the C++ standard library, though in different headers.

Extended precision refers to floating-point number formats that provide greater precision than the basic floating-point formats. Extended precision formats support a basic format by minimizing roundoff and overflow errors in intermediate values of expressions on the base format. In contrast to extended precision, arbitrary-precision arithmetic refers to implementations of much larger numeric types using special software.

In computer science, a type punning is any programming technique that subverts or circumvents the type system of a programming language in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal language.

In computing, quadruple precision is a binary floating-point–based computer number format that occupies 16 bytes with precision at least twice the 53-bit double precision.

C11 is an informal name for ISO/IEC 9899:2011, a past standard for the C programming language. It replaced C99 and has been superseded by C17. C11 mainly standardizes features already supported by common contemporary compilers, and includes a detailed memory model to better support multiple threads of execution. Due to delayed availability of conforming C99 implementations, C11 makes certain features optional, to make it easier to comply with the core language standard.

C17 is the informal name for ISO/IEC 9899:2018, the most recent standard for the C programming language, prepared in 2017 and published in June 2018. It replaced C11, and will be superseded by C23 when it is published in 2024. Since it was under development in 2017, and officially published in 2018, C17 is sometimes referred to as C18.

C23 is the informal name for ISO/IEC 9899:2024, the next standard for the C programming language, which will replace C17. It was started in 2016 informally as C2x, and expected to be published in 2024. The most recent publicly available working draft of C23 was released on April 1, 2023. The first WG14 meeting for the C2x draft was held in October 2019, virtual remote meetings were held in 2020 due to the COVID-19 pandemic, then various teleconference meetings continued to occur through 2024.

References

  1. "ISO/IEC 9899:1999 - Programming languages - C". Iso.org. 8 December 2011. Retrieved 8 April 2014.
  2. 1 2 "IEEE 754 Support in C99" (PDF). grouper.ieee.org. Archived from the original (PDF) on 28 October 2017. Retrieved 15 July 2021.
  3. "Standards - Using the GNU Compiler Collection (GCC)". Gcc.gnu.org. Retrieved 8 April 2014.
  4. "C Dialect Options - Using the GNU Compiler Collection (GCC)". Gcc.gnu.org. 6 May 2009. Retrieved 8 April 2014.
  5. "Using the GNU Compiler Collection (GCC): Designated Initializers". gnu.org. Retrieved 18 September 2019.
  6. "Using the GNU Compiler Collection (GCC): Compound Literals". gnu.org. Retrieved 31 January 2016.
  7. Ulrich Drepper (23 October 2007). "What every programmer should know about memory". LWN.net . Retrieved 3 April 2015.
  8. ISO/IEC 9899:1999 specification, TC3 (PDF). p. 119, § 6.7.5.3 Function declarators (including prototypes) para. 7.
  9. Doug Priest (1997). "Differences Among IEEE 754 Implementations".
  10. Jack Woehr (1 November 1997). "A conversation with William Kahan".
  11. William Kahan (11 June 1996). "The Baleful Effect of Computer Benchmarks upon Applied Mathematics, Physics and Chemistry" (PDF).
  12. William Kahan (11 January 2006). "How Futile are Mindless Assessments of Roundoff in Floating-Point Computation?" (PDF).
  13. Peter Bright (29 June 2013). "C99 acknowledged at last as Microsoft lays out its path to C++14". Ars Technica . Retrieved 9 January 2015.
  14. 1 2 3 Brenner, Pat. "What's New for Visual C++ in Visual Studio 2015". Microsoft Developer Network. Retrieved 27 April 2015.
  15. "Using the x86 Open64 Compiler Suite" (PDF). Developer.amd.com. Archived (PDF) from the original on 24 January 2022. Retrieved 2 March 2022.
  16. "cc65 - a freeware C compiler for 6502 based systems" . Retrieved 14 September 2011.
  17. "C/C++ interpreter Ch C99 features". SoftIntegration, Inc. 15 February 2008. Retrieved 15 February 2008.
  18. "Clang Compiler User's Manual" . Retrieved 14 October 2017.
  19. "The CompCert C verified compiler documentation and user's manual (Version 3.10)". 19 November 2021. Retrieved 3 March 2022.
  20. "libfirm homepage" . Retrieved 4 February 2014.
  21. "C Language Implementation - Digital Mars" . Retrieved 14 September 2011.
  22. "Status of C99 features in GCC". Free Software Foundation, Inc. 28 July 2021. Retrieved 13 August 2021.
  23. "Status of C99 features in GCC 4.6". Free Software Foundation, Inc. 23 May 2013. Retrieved 23 May 2013.
  24. "Status of C99 features in GCC 4.7". Free Software Foundation, Inc. 23 May 2013. Retrieved 23 May 2013.
  25. "Semantics of Floating Point Math in GCC". 20 July 2018. Retrieved 12 August 2018.
  26. "IBM C for AIX, V6.0 Now Supports the C99 Standard". 2 July 2002. Retrieved 31 January 2016.
  27. "IBM - XL C/C++ for AIX" . Retrieved 31 January 2016.
  28. "IBM Rational Logiscope support for C99 standard - United States". 24 February 2012. Retrieved 31 January 2016.
  29. "Reader Q&A: What about VC++ and C99?". Sutter’s Mill. 3 May 2012. Retrieved 31 January 2016.
  30. "A.27 Use of C99 Variable Length Arrays". Microsoft. Retrieved 31 January 2016.
  31. "Microsoft to C99 Developers: Use ISO C++". InfoQ. Retrieved 31 January 2016.
  32. "C99 library support in Visual Studio 2013". Microsoft. 19 July 2013. Retrieved 31 January 2016.
  33. "C++11/14 STL Features, Fixes, And Breaking Changes In VS 2013". Blogs.msdn.com. 28 June 2013. Retrieved 8 April 2014.
  34. "Announcing full support for a C/C++ conformant preprocessor in MSVC". Microsoft. 27 March 2020. Retrieved 17 September 2020.
  35. "C99 compliance in Open Watcom". Archived from the original on 3 May 2015. Retrieved 25 September 2015.
  36. "Pelles C Overview". January 2013. Archived from the original on 13 March 2022. Retrieved 2 March 2022.
  37. "Sun Studio 12: C Compiler 5.9 Readme". Sun Microsystems, Inc. 31 May 2007. Retrieved 23 September 2012.
  38. "Tiny C Compiler Reference Documentation" . Retrieved 31 January 2016.
  39. According to the project's TODO list complex types are the only missing C99 feature. Variable Length Arrays have been added in TCC 0.9.26
  40. "TCC : Tiny C Compiler" . Retrieved 31 January 2016.
  41. "Standards - Using the GNU Compiler Collection (GCC)". Gcc.gnu.org. Retrieved 8 April 2014.

Further reading

Preceded by C language standards Succeeded by
C11