diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-09-19 23:17:44 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-09-19 23:17:44 +0000 |
commit | 0c706c29f20b6fa36759fa41333b9c3ec0bd2969 (patch) | |
tree | cff749b4d8a9d6e5b4fbae39c4f4e710307366c0 /docs/LanguageExtensions.html | |
parent | 40ccaccd21a4377cd76d6adda2b192dcf9514ef6 (diff) |
Add list initialization for complex numbers in C. Essentially, this allows "_Complex float x = {1.0f, 2.0f};". See changes to docs/LanguageExtensions.html for a longer description.
<rdar://problem/9397672>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140090 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/LanguageExtensions.html')
-rw-r--r-- | docs/LanguageExtensions.html | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index 685544f53f..0a0ada465e 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -4,7 +4,7 @@ <html> <head> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> - <title>Clang LanguageExtensions</title> + <title>Clang Language Extensions</title> <link type="text/css" rel="stylesheet" href="../menu.css"> <link type="text/css" rel="stylesheet" href="../content.css"> <style type="text/css"> @@ -85,6 +85,7 @@ </ul> </li> <li><a href="#overloading-in-c">Function Overloading in C</a></li> +<li><a href="#complex-list-init">Initializer lists for complex numbers in C</a></li> <li><a href="#builtins">Builtin Functions</a> <ul> <li><a href="#__builtin_shufflevector">__builtin_shufflevector</a></li> @@ -895,6 +896,41 @@ caveats to this use of name mangling:</p> <p>Query for this feature with __has_extension(attribute_overloadable).</p> +<!-- ======================================================================= --> +<h2 id="complex-list-init">Initializer lists for complex numbers in C</h2> +<!-- ======================================================================= --> + +<p>clang supports an extension which allows the following in C:</p> + +<blockquote> +<pre> +#include <math.h> +#include <complex.h> +complex float x = { 1.0f, INFINITY }; // Init to (1, Inf) +</pre> +</blockquote> + +<p>This construct is useful because there is no way to separately +initialize the real and imaginary parts of a complex variable in +standard C, given that clang does not support <code>_Imaginary</code>. +(clang also supports the <code>__real__</code> and <code>__imag__</code> +extensions from gcc, which help in some cases, but are not usable in +static initializers.) + +<p>Note that this extension does not allow eliding the braces; the +meaning of the following two lines is different:</p> + +<blockquote> +<pre> +complex float x[] = { { 1.0f, 1.0f } }; // [0] = (1, 1) +complex float x[] = { 1.0f, 1.0f }; // [0] = (1, 0), [1] = (1, 0) +</pre> +</blockquote> + +<p>This extension also works in C++ mode, as far as that goes, but does not + apply to the C++ <code>std::complex</code>. (In C++11, list + initialization allows the same syntax to be used with + <code>std::complex</code> with the same meaning.) <!-- ======================================================================= --> <h2 id="builtins">Builtin Functions</h2> |