(complex numbers) |
|||
Line 58: | Line 58: | ||
Which outputs | Which outputs | ||
-16.000000 + 0.000000i | -16.000000 + 0.000000i | ||
+ | |||
+ | == Type-generic math == | ||
+ | {{main|tgmath.h - C|l1=<tgmath.h>}} | ||
+ | C99 introduce the [[tgmath.h - C|<tgmath.h>]] header which provide [[generic selection - C|type-generic macros]] that determine the function depending on the arguments provided. | ||
+ | |||
+ | == Extended identifiers == | ||
+ | {{main|Extended identifiers - C|l1=Extended identifiers}} | ||
+ | C99 brought support for extended identifiers and extended characters. For example: | ||
+ | |||
+ | <source lang="C"> | ||
+ | #include <stdio.h> | ||
+ | void שלום() { puts("Hello"); } | ||
+ | int main() | ||
+ | { | ||
+ | שלום(); | ||
+ | \u05E9\u05DC\u05D5\u05DD(); | ||
+ | return 0; | ||
+ | } | ||
+ | </source> | ||
== Compiler support == | == Compiler support == | ||
Line 70: | Line 89: | ||
| ACK || style="background:#FF6666;text-align:center;" | No Support || || | | ACK || style="background:#FF6666;text-align:center;" | No Support || || | ||
|- | |- | ||
− | | Clang || style="background:#99FF66;text-align:center;" | Complete || style="text-align:center;" | -std=c99 || | + | | Clang || style="background:#99FF66;text-align:center;" | Complete || style="text-align:center;" | -std=c99 || Supports everything<ref>[http://p99.gforge.inria.fr/c99-conformance/c99-conformance-clang-3.2.html C99 Conformance CLANG Test]</ref> |
|- | |- | ||
| GCC || style="background:#99FF66;text-align:center;" | Complete || style="text-align:center;" | -std=c99 || Supports everything<ref>[http://p99.gforge.inria.fr/c99-conformance/c99-conformance-gcc-4.7.html C99 Conformance GCC Test]</ref> | | GCC || style="background:#99FF66;text-align:center;" | Complete || style="text-align:center;" | -std=c99 || Supports everything<ref>[http://p99.gforge.inria.fr/c99-conformance/c99-conformance-gcc-4.7.html C99 Conformance GCC Test]</ref> |
Revision as of 14:05, 23 December 2013
C99 is a past version of the C programming language standard which was ratified by ISO in 1999 and became ISO/IEC 9899:1999. The same standard was later also adopted by ANSI on May 22, 2000. C99 cancels and replaces the first edition, C89, and NA1.
C99 brought the first major updates to the language in a decade. The new standard introduced restricted pointers, variable-length arrays, flexible array members, complex numbers support, type-generic math, long long int
, extended identifiers, hexadecimal floating-point constants, compound literals, designated initializers, single line, //
comments, extended integer type, the ability to mix declarations and code, variadic macros, new math functions, inline functions, boolean types, _Pragma and standard pragmas, and VA_COPY. The standard also removed implicit function declaration.
Contents
Version detection
C99 can be detected via the __STDC_VERSION__ mandatory macro which must equal 199901L
.
#if __STDC_VERSION__ >= 199901L
/* C99 support */
#endif
New headers
C99 introduced 6 new standard headers: <tgmath.h>, <stdint.h>, <stdbool.h>, <inttypes.h>, <fenv.h>, and <complex.h>.
Restricted pointers
- Main article: Restricted pointers
C99 introduced the concept of restricted pointer to the C language through the introduction of the restrict keyword. Given two pointers, if they do not point to two distinct objects, they are said to be aliases. The restrict keyword establishes a special association between the pointer and the object it accesses, guaranteeing all accesses to the object it points to occur through that pointer or expressions based on that pointer.
Since multiple pointers can point to the same object, compilers are often unable to make certain optimizations that require them to know that only a specific pointer has access to the object it points to. The restrict keyword was designed to aid such compiler issues. Consequently, various functions such as memcpy(), strcpy(), and strcat() have had their signatures changed to:
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
char *strcpy(char * restrict s1, const char * restrict s2);
char *strcat(char * restrict s1, const char * restrict s2);
Variable-length array
- Main article: Variable length arrays
Variable-length array (VLA) are arrays of automatic storage whose size is determined at run-time. C99 introduced support for variable-length arrays. The length of the array does not change throughout the duration of the object's lifetime.
int foo(size_t len)
{
int bar[len];
something(bar);
return bar[0];
}
Complex numbers
- Main article: Complex numbers
C99 brought support for complex numbers including a set of functions for dealing with complex numbers which can be found in <complex.h>. For example,
#include <stdio.h>
#include <complex.h>
int main()
{
double complex val = 4 * I;
val = cpow(val, 2);
printf("%f + %fi\n", creal(val), cimag(val));
return 0;
}
Which outputs
-16.000000 + 0.000000i
Type-generic math
- Main article: <tgmath.h>
C99 introduce the <tgmath.h> header which provide type-generic macros that determine the function depending on the arguments provided.
Extended identifiers
- Main article: Extended identifiers
C99 brought support for extended identifiers and extended characters. For example:
#include <stdio.h>
void שלום() { puts("Hello"); }
int main()
{
שלום();
\u05E9\u05DC\u05D5\u05DD();
return 0;
}
Compiler support
Support for C99 has been a slow ongoing effort.
C99 Compiler Support | |||
Compiler Name | Support Level | Enforcement Switch | Note |
---|---|---|---|
ACK | No Support | ||
Clang | Complete | -std=c99 | Supports everything[1] |
GCC | Complete | -std=c99 | Supports everything[2] |
TCC | Partial | Missing lots of features[3] | |
ICC | Partial | -std=c99 | Broken extended identifier support, broken inline function support[4] |
Visual C++ | Partial | Missing type-generic math[5] |