On Fri, Sep 28, 2007 at 06:47:09PM +0200, Marc Andre Tanner wrote: > struct in6_addr { > union { > uint8_t u6_addr8 [ 16 ] ; > uint16_t u6_addr16 [ 8 ] ; > uint32_t u6_addr32 [ 4 ] ; > } in6_u ; > } ; [...] > IPADDR ip4_any = { > 2, > { ( ( in_addr_t ) 0x00000000 ) } // broken > // { ( in_addr_t ) 0x00000000 } // this would work > };
Two things to note about this: - It's making use of a gcc language extension. Proper C would require at least some additional braces around that initializer value. - Even with gcc's initializer extension, it only produces the "correct" result as a side effect. The lack of a designated initializer means that the initializer value gets assigned only to the very first thing in the union. The 32-bit (in_addr_t)0 is truncated to 8 bits and assigned to u6_addr8[0]. The remaining 15 elements of u6_addr8[] are implicitly zero-filled just like any other integer array that only had its first element initialized. The cast to in_addr_t is misleading, because it's not going to store 32 bits in the union and if you try to use any value _other_ than 0 you may not get what you want. For example if you try something like 0xffffffff it will assign 0xff to only the first byte of the union and zero-fill the other 15. -Dave Dodge _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel