From owner-freebsd-hackers Wed Feb 21 7:56:36 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from rover.village.org (rover.bsdimp.com [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id B796E37B6A1 for ; Wed, 21 Feb 2001 07:56:32 -0800 (PST) (envelope-from imp@billy-club.village.org) Received: from billy-club.village.org (billy-club.village.org [10.0.0.3]) by rover.village.org (8.11.2/8.11.0) with ESMTP id f1LFuTh63040; Wed, 21 Feb 2001 08:56:29 -0700 (MST) (envelope-from imp@billy-club.village.org) Received: from billy-club.village.org (localhost [127.0.0.1]) by billy-club.village.org (8.11.2/8.8.3) with ESMTP id f1LFrvs07412; Wed, 21 Feb 2001 08:53:57 -0700 (MST) Message-Id: <200102211553.f1LFrvs07412@billy-club.village.org> To: "Jacques A. Vidrine" Subject: Re: portability sanity check Cc: freebsd-hackers@FreeBSD.ORG In-reply-to: Your message of "Wed, 21 Feb 2001 09:42:29 CST." <20010221094228.A93221@hamlet.nectar.com> References: <20010221094228.A93221@hamlet.nectar.com> Date: Wed, 21 Feb 2001 08:53:57 -0700 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. There are times that you'd want to do this (like generic list routines), but such type punning, as this is known, is error prone and can lead to problems. It is best avoided in favor of macros, unions or some other less error prone technique. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message