diff options
author | Jakub Jelinek <jakub@redhat.com> | 2001-12-12 20:12:16 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2001-12-12 20:12:16 +0100 |
commit | 59c83dbf283e0dcf89ecfcfcbab856682291842a (patch) | |
tree | 52579c466b178af3b34b3b7f1c35b83542ee7516 /gcc/doc | |
parent | 3af37d3f59fae068635c004403868f317eb732af (diff) | |
download | gcc-59c83dbf283e0dcf89ecfcfcbab856682291842a.zip gcc-59c83dbf283e0dcf89ecfcfcbab856682291842a.tar.gz gcc-59c83dbf283e0dcf89ecfcfcbab856682291842a.tar.bz2 |
c-typeck.c (digest_init): Allow initializing static storage duration objects with compound literals.
* c-typeck.c (digest_init): Allow initializing
static storage duration objects with compound literals.
* doc/extend.texi (Compound literals): Document the extension.
* gcc.dg/gnu89-init-1.c: New test.
From-SVN: r47945
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 80addd3..9b97805 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -1649,6 +1649,30 @@ Compound literals for scalar types and union types are is also allowed, but then the compound literal is equivalent to a cast. +As a GNU extension, GCC allows initialization of objects with static storage +duration by compound literals (which is not possible in ISO C99, because +the initializer is not a constant). +It is handled as if the object was initialized only with the bracket +enclosed list if compound literal's and object types match. +The initializer list of the compound literal must be constant. +If the object being initialized has array type of unknown size, the size is +determined by compound literal's initializer list, not by the size of the +compound literal. + +@example +static struct foo x = (struct foo) @{1, 'a', 'b'@}; +static int y[] = (int []) @{1, 2, 3@}; +static int z[] = (int [3]) @{1@}; +@end example + +@noindent +The above lines are equivalent to the following: +@example +static struct foo x = @{1, 'a', 'b'@}; +static int y[] = @{1, 2, 3@}; +static int z[] = @{1@}; +@end example + @node Designated Inits @section Designated Initializers @cindex initializers with labeled elements |