Date: Tue, 04 Aug 1998 14:43:21 -0700 From: Ted Faber <faber@ISI.EDU> To: Warner Losh <imp@village.org> Cc: Nicolas Souchu <Nicolas.Souchu@prism.uvsq.fr>, FreeBSD Hackers <freebsd-hackers@FreeBSD.ORG> Subject: Re: C and static initialization with unions Message-ID: <199808042143.OAA15441@tnt.isi.edu> In-Reply-To: Your message of "Tue, 04 Aug 1998 13:50:49 MDT." <199808041950.NAA18579@harmony.village.org>
next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE----- Warner Losh wrote: >In message <19980804185938.36803@breizh.prism.uvsq.fr> Nicolas Souchu writes: >: static union foo_t bar = { (void *)&anyvar }; >: >: The compiler says "warning, making integer from pointer without a cast"... >: Which is true and could lead to bad asm code. > >static union foo_t bar = { (int)(void *)&anyvar }; > >But it is unwise to assume that sizeof(int) == sizeof(void *). The comp.lang.c FAQ (http://www.eskimo.com/~scs/C-faq/top.html) suggests putting the member he wants to initialize first in the union, where a conformant ANSI C compiler will initialize it correctly. (http://www.eskimo.com/~scs/C-faq/q2.20.html) Initializing with that cast defeats the point of using a union at all. Not that this belongs in hackers... - ---------------------------------------------------------------------- Ted Faber faber@isi.edu USC/ISI Computer Scientist http://www.isi.edu/~faber (310) 822-1511 x190 PGP Key: http://www.isi.edu/~faber/pubkey.asc -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBNceAeIb4eisfQ5rpAQFWIAQAsfm+uom56JCQN1Y16/Uhg2nYB5YpkbgN 51r1pYyVTtjkOTJawORnbYHdTPT/648ySX7WZFTXb9mJEook50Ue0YaesF83SlIN n4SLsD9wPOMTNrzZZEXihecS9HTXfcWzaaeMfNhIlUycKc6O5DGScU0Hkq18UQvZ 2sNiG8qd1oE= =cYvz -----END PGP SIGNATURE----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808042143.OAA15441>