<div dir="ltr">On Mon, Apr 22, 2013 at 10:33 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Hi,<div><br></div><div>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.</div>
</div></blockquote><div><br></div><div style>GCC is correct; see <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm">http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm</a></div><div style><br></div>
<div style>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."</div>
<div style><br></div><div style>So the example is equivalent to</div><div style><br></div><div style>int x[1][3] = {[0][2] = 7, [0] = {10, 11, 0}};</div><div style><br></div><div style>and the initializer for x[0][2] from the second init list overrides the first initializer by 6.7.8/19.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>#include <stdio.h></div>
<div><br></div><div>int main() {</div><div>  int x[1][3] = {[0][2] = 7, [0] = {10, 11}};</div><div>  printf("%d %d %d\n", x[0][0], x[0][1], x[0][2]);</div>

<div>}</div></div><div><br></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>