From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 5 10:05:48 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 824FA1065670; Sun, 5 Jun 2011 10:05:48 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 5E6828FC08; Sun, 5 Jun 2011 10:05:48 +0000 (UTC) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id 0B7E046B24; Sun, 5 Jun 2011 06:05:48 -0400 (EDT) Date: Sun, 5 Jun 2011 11:05:47 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: mdf@FreeBSD.org In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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: Sun, 05 Jun 2011 10:05:48 -0000 On Tue, 31 May 2011, 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. > > 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 *) == > 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). I think you're OK for MFC purposes, but that in general, we shouldn't assume that they are the same size. I.e., we should use a function pointer type where we mean a function pointer type, and never write code that casts a function pointer to a regular pointer. (Which the change is fine with respect to, I believe). I'm doing some research on an experimental architecture where certain types of function pointers are 256-bit. This has some interesting consequences; we haven't yet gotten to investigating C language extensions/compatibility, but that will follow in the next year or so. (We also have 256-bit data references, similar to pointers, for use in some environments, which will also prove interesting. I'm not yet convinced we'll try to use a general pointer type for them, but perhaps instead extend the language to have a qualified type of some sort). Robert