On Fri, May 29, 2009 at 08:07:34PM +0100, Philip Martin wrote: > It may be idiomatic but it's not strictly valid and the warning > appears to be correct. For example see: > > https://bugzilla.redhat.com/show_bug.cgi?id=448743 > > which shows that the generated code may not be what you want, and also > suugests how to modify the source code to be valid. It's still my opinion that this is an acceptable usage that is permitted by POSIX, even if not by ISO C [0]: The <sys/socket.h> header shall define the sockaddr_storage structure. This structure shall be: * Large enough to accommodate all supported protocol-specific address structures * Aligned at an appropriate boundary so that pointers to it can be cast as pointers to protocol-specific address structures and used to access the fields of those structures without alignment problems Please note: "pointers to [sockaddr_storage] can be cast as pointers to protocol-specific address structures and used to access the fields of those structures". Also [0]: When a sockaddr_storage structure is cast as a sockaddr structure, the ss_family field of the sockaddr_storage structure shall map onto the sa_family field of the sockaddr structure. When a sockaddr_storage structure is cast as a protocol-specific address structure, the ss_family field shall map onto a field of that structure that is of type sa_family_t and that identifies the protocol's address family. Obviously, POSIX intends code similar to the code I provided. I expect that when used on a POSIX system (at least in strict POSIX mode or when invoked as "c99"), gcc-4.4 neither warns nor generates code contrary to POSIX with -O2 -Wall. It may happen that the proper place to fix this may be glibc; I believe there's a way to indicate to GCC that a type may alias any other type, which may solve this problem. If that's the case, feel free to reassign this bug there. If you believe POSIX is in error, please keep the bug and I in the loop with respect to the defect report. [0] http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/socket.h.html -- brian m. carlson / brian with sandals: Houston, Texas, US +1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Attachment:
signature.asc
Description: Digital signature