From owner-freebsd-hackers Wed Feb 21 8:22:10 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from gw.nectar.com (gw.nectar.com [208.42.49.153]) by hub.freebsd.org (Postfix) with ESMTP id B064037B698 for ; Wed, 21 Feb 2001 08:22:05 -0800 (PST) (envelope-from nectar@nectar.com) Received: from hamlet.nectar.com (hamlet.nectar.com [10.0.1.102]) by gw.nectar.com (Postfix) with ESMTP id 832C718C92; Wed, 21 Feb 2001 10:22:00 -0600 (CST) Received: (from nectar@localhost) by hamlet.nectar.com (8.11.2/8.9.3) id f1LGM0U93541; Wed, 21 Feb 2001 10:22:00 -0600 (CST) (envelope-from nectar@spawn.nectar.com) Date: Wed, 21 Feb 2001 10:22:00 -0600 From: "Jacques A. Vidrine" To: Poul-Henning Kamp Cc: Warner Losh , freebsd-hackers@FreeBSD.ORG Subject: Re: portability sanity check Message-ID: <20010221102200.A93525@hamlet.nectar.com> Mail-Followup-To: "Jacques A. Vidrine" , Poul-Henning Kamp , Warner Losh , freebsd-hackers@FreeBSD.ORG References: <200102211553.f1LFrvs07412@billy-club.village.org> <2056.982772015@critter> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <2056.982772015@critter>; from phk@critter.freebsd.dk on Wed, Feb 21, 2001 at 05:13:35PM +0100 X-Url: http://www.nectar.com/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, Feb 21, 2001 at 05:13:35PM +0100, Poul-Henning Kamp wrote: > In message <200102211553.f1LFrvs07412@billy-club.village.org>, Warner Losh writes: > >In message <20010221094228.A93221@hamlet.nectar.com> "Jacques A. Vidrine" writes: > >: Likewise if the first member were a more complex data type, but > >: nevertheless the same between the different structures. > >: > >: It seems safe to me, but I can't explain why :-) > > > >It is obfuscated 'C', but it is safe. The standard requires that > >(void *) &foo == (void *) &foo->s and that if s were a complex > >structure that it be laid out the same in all instances of s. So I > >think that it is "safe" to do that. > > Safe, but stupid, since type-safety is lost when doing so. Type-safety is a cruch for the weak-minded. :-) But seriously I think that for the purpose of building a utility function for use by qsort or similar, using a union just for such a purpose is more obfuscated. struct nothing_much_in_common_really { const char *s; union { struct foo foo; struct bar bar; } u; }; But if there is a better way, I'm all ears :-) Cheers, -- Jacques Vidrine / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message