[cfe-dev] Designated initializer incompatibility
Richard Smith
richard at metafoo.co.uk
Tue Apr 23 06:40:35 PDT 2013
On Mon, Apr 22, 2013 at 10:33 PM, Rui Ueyama <ruiu at google.com> wrote:
> Hi,
>
> The following code outputs "10 11 0" with GCC, but "10 11 7" with Clang.
> Is there anyone who knows which is correct? The C99 spec seems to be a bit
> unclear about this.
>
GCC is correct; see
http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm
C99 6.7.8/21 says: "If there are fewer initializers in a brace-enclosed
list than there are elements or members of an aggregate, [...] the
remainder of the aggregate shall be initialized implicitly the same as
objects that have static storage duration."
So the example is equivalent to
int x[1][3] = {[0][2] = 7, [0] = {10, 11, 0}};
and the initializer for x[0][2] from the second init list overrides the
first initializer by 6.7.8/19.
#include <stdio.h>
>
> int main() {
> int x[1][3] = {[0][2] = 7, [0] = {10, 11}};
> printf("%d %d %d\n", x[0][0], x[0][1], x[0][2]);
> }
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130423/52e469bf/attachment.html>
More information about the cfe-dev
mailing list