From owner-freebsd-standards Tue May 28 20:43:53 2002 Delivered-To: freebsd-standards@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 931) id 79EF937B401; Tue, 28 May 2002 20:43:50 -0700 (PDT) Date: Tue, 28 May 2002 20:43:50 -0700 From: "J. Mallett" To: Garrett Wollman Cc: standards@FreeBSD.ORG Subject: Re: Q&D implementation of dlfunc() Message-ID: <20020528204350.B74072@FreeBSD.ORG> References: <20020528195236.A66528@FreeBSD.ORG> <200205290340.g4T3erxr010138@khavrinen.lcs.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <200205290340.g4T3erxr010138@khavrinen.lcs.mit.edu>; from wollman@khavrinen.lcs.mit.edu on Tue, May 28, 2002 at 11:40:53PM -0400 Organisation: The FreeBSD Project X-Alternate-Addresses: , , , X-Affiliated-Projects: FreeBSD, xMach, ircd-hybrid-7 X-Towel: Yes 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 * From Garrett Wollman > < said: > > > rv = (uintptr_t)dlsym(handle, symbol); > > For the same reason as you can't cast from a data pointer to a > function pointer, there's no guarantee that you can cast from a > uintptr_t (if such a type even exists) to a function pointer. Since > we're depending on all pointers having the same representation, I'd > rather make it explicit. Right, I understand the situation, and how evil it is. Look at the code I put below, I think I forgot to include parts of my hello world, which removes that assumption, by doing (note inocrrectness of hello was to deal with having prototypes in scope, I could have done something cleaner, but...): convptr hello(convptr function, uintptr_t *data) { printf("## hello: %p, %p\n", function, data); printf("Hello, world!\n"); return function; } int main(int argc, char *argv[]) { convptr foo, bar; uintptr_t data[sizeof(convptr)/sizeof(uintptr_t)]; printf("## main: 0x%x, %p\n", argc, argv); function_to_data_ptr((convptr)data_to_function_ptr, data); data_to_function_ptr(&foo, data); function_to_data_ptr((convptr)hello, data); (*foo)(&bar, data); (*bar)(NULL, NULL); return 0; } -- J. Mallett FreeBSD: The Power To Serve To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message