From owner-freebsd-hackers Tue Aug 4 14:43:45 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA00258 for freebsd-hackers-outgoing; Tue, 4 Aug 1998 14:43:45 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from tnt.isi.edu (tnt.isi.edu [128.9.128.128]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA00252 for ; Tue, 4 Aug 1998 14:43:41 -0700 (PDT) (envelope-from faber@ISI.EDU) Received: from ISI.EDU (vex-e.isi.edu [128.9.160.240]) by tnt.isi.edu (8.8.7/8.8.6) with ESMTP id OAA15441; Tue, 4 Aug 1998 14:43:22 -0700 (PDT) Message-Id: <199808042143.OAA15441@tnt.isi.edu> To: Warner Losh Cc: Nicolas Souchu , FreeBSD Hackers Subject: Re: C and static initialization with unions In-Reply-To: Your message of "Tue, 04 Aug 1998 13:50:49 MDT." <199808041950.NAA18579@harmony.village.org> X-Url: http://www.isi.edu/~faber Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 04 Aug 1998 14:43:21 -0700 From: Ted Faber Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG -----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