struct test_1 {<br /> int (*t1)(void);<br /> int (*t2)(void);<br />};<br />struct test_2 {<br /> int (*t1)(void);<br />};<br />struct test {<br /> union {<br /> struct test_1 t1;<br /> struct test_2 t2;<br /> } u;<br /> int dummy;<br />};<br />static int foo(void){return 0;};<br />static struct test t = {<br /> { {<br /> foo,<br /> foo,<br /> } },<br /> 0,<br />}; struct test_1 {<br /> int (*t1)(void);<br /> int (*t2)(void);<br />};<br />struct test_2 {<br /> int (*t1)(void);<br />};<br />struct test {<br /> union {<br /> struct test_2 t2;<br /> struct test_1 t1;<br /> } u;<br /> int dummy;<br />};<br />static int foo(void){return 0;};<br />static struct test t = {<br /> { {<br /> foo,<br /> foo,<br /> } },<br /> 0,<br />};
看出區別了嗎?看出問題了嗎?試試吧。
結論:(From C-FAQ) In the original ANSI C, an initializer was allowed only for the first-named member of a union. C99 introduces ``designated initializers'' which can be used to initialize any member.