From owner-freebsd-standards Tue May 28 19:48:59 2002 Delivered-To: freebsd-standards@freebsd.org Received: from chiark.greenend.org.uk (chiark.greenend.org.uk [212.135.138.206]) by hub.freebsd.org (Postfix) with ESMTP id A348437B400; Tue, 28 May 2002 19:48:53 -0700 (PDT) Received: from fanf by chiark.greenend.org.uk with local (Exim 3.12 #1) id 17CtW5-0000G3-00 (Debian); Wed, 29 May 2002 03:48:49 +0100 Date: Wed, 29 May 2002 03:48:49 +0100 From: Tony Finch To: Garrett Wollman Cc: standards@freebsd.org, jdp@freebsd.org Subject: Re: Q&D implementation of dlfunc() Message-ID: <20020529034849.A30428@chiark.greenend.org.uk> References: <200205290223.g4T2NOMD009676@khavrinen.lcs.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200205290223.g4T2NOMD009676@khavrinen.lcs.mit.edu>; from wollman@khavrinen.lcs.mit.edu on Tue, May 28, 2002 at 10:23:24PM -0400 Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, May 28, 2002 at 10:23:24PM -0400, Garrett Wollman wrote: > Those who follow the Austin Group lists will be aware of an issue > raised (and not resolved there) about the unsuitability of the return > type of dlsym() for its most common use. They've also been arguing about it on comp.std.c. > +/* > + * The actual type declared by this typedef is immaterial, provided that > + * it is a function pointer. Its purpose is to provide a return type for > + * dlfunc() which can be cast to a function pointer type without depending > + * on behavior undefined by the C standard which might trigger a compiler > + * diagnostic. We intentionally declare a very unlikely type signature > + * to force a diagnostic should the application not cast the return value > + * of dlfunc() appropriately. > + */ > +typedef void (*__dlfunc_t)(void (*)(char, short, int, ...)); I'd be inclined to be less obfuscated by using a structure type to "guarantee" the uniqueness of the argument type of __dlfunc_t -- something like struct __dlfunc_arg { int dummy; }; typedef void (*__dlfunc_t)(struct __dlfunc_arg); and s/We .*/We use a unique structure as the argument type/. (The structure type could be made truly unique by declaring it in the argument list itself, but compilers will rightly warn about this since it makes the resulting function type unusable -- which is what we want except for the warning.) What does "Q&D" mean? Tony. -- f.a.n.finch http://dotat.at/ HEBRIDES BAILEY: CYCLONIC OR SOUTHEASTERLY BECOMING SOUTHWESTERLY, 4 OR 5, OCCASIONALLY 6 LATER. RAIN OR SHOWERS. MODERATE OR GOOD. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message