From owner-freebsd-hackers@FreeBSD.ORG Tue May 31 23:23:41 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7013106566B; Tue, 31 May 2011 23:23:41 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 64BE78FC15; Tue, 31 May 2011 23:23:41 +0000 (UTC) Received: from [10.0.0.63] (63.imp.bsdimp.com [10.0.0.63]) (authenticated bits=0) by harmony.bsdimp.com (8.14.4/8.14.3) with ESMTP id p4VNIG5h017858 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES128-SHA bits=128 verify=NO); Tue, 31 May 2011 17:18:18 -0600 (MDT) (envelope-from imp@bsdimp.com) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: Date: Tue, 31 May 2011 17:18:16 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: mdf@freebsd.org X-Mailer: Apple Mail (2.1084) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (harmony.bsdimp.com [10.0.0.6]); Tue, 31 May 2011 17:18:18 -0600 (MDT) Cc: freebsd-hackers , Bruce Evans Subject: Re: sizeof(function pointer) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2011 23:23:41 -0000 On May 31, 2011, at 5:07 PM, mdf@freebsd.org wrote: > I am looking into potentially MFC'ing r212367 and related, that adds > drains to sbufs. The reason for MFC is that several pieces of new > code in CURRENT are using the drain functionality and it would make > MFCing those changes much easier. >=20 > The problem is that r212367 added a pointer to a drain function in the > sbuf (it replaced a pointer to void). The C standard doesn't > guarantee that a void * and a function pointer have the same size, > though its true on amd64, i386 and I believe PPC. What I'm wondering > is, though not guaranteed by the standard, is it *practically* true > that sizeof(void *) =3D=3D sizeof(int(*)(void)), such that an MFC = won't > break binary compatibility for any supported architecture? (The > standard does guarantee, though not in words, that all function > pointers have the same size, since it guarantees that pointers to > functions can be cast to other pointers to functions and back without > changing the value). >=20 > Another possibility is to malloc a blob that is sizeof(int(*)(void)) > and store that in a renamed s_unused; this is a bit messier but > guaranteed to work. I'd just rather the code be an MCF instead of a > partial re-write. It is the same on MIPS too for all three ABIs that we support (and all = ABIs that I know about). It is true on ARM as well. Usually it is different only on segmented architectures like 16-bit x86. Warner=