From owner-freebsd-hackers Wed Feb 21 7:43:26 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 02EF637B69B for ; Wed, 21 Feb 2001 07:42:45 -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 3000F18C91 for ; Wed, 21 Feb 2001 09:42:29 -0600 (CST) Received: (from nectar@localhost) by hamlet.nectar.com (8.11.2/8.9.3) id f1LFgT993374 for freebsd-hackers@freebsd.org; Wed, 21 Feb 2001 09:42:29 -0600 (CST) (envelope-from nectar@spawn.nectar.com) Date: Wed, 21 Feb 2001 09:42:29 -0600 From: "Jacques A. Vidrine" To: freebsd-hackers@freebsd.org Subject: portability sanity check Message-ID: <20010221094228.A93221@hamlet.nectar.com> Mail-Followup-To: "Jacques A. Vidrine" , freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Url: http://www.nectar.com/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Is the following portable and safe? Given n different structure declarations, where each structure begins with the same member type, can any instance of any of the structures be cast to the (pointer) type of the first member? e.g. struct foo { const char *s; ... }; struct bar { const char *s; ... }; int gefahr(struct foo *Foo, struct bar *Bar) { return strcmp((const char *s)Foo, (const char *s)Bar); } 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 :-) 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