Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 May 2002 20:43:50 -0700
From:      "J. Mallett" <jmallett@FreeBSD.org>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        standards@FreeBSD.ORG
Subject:   Re: Q&D implementation of dlfunc()
Message-ID:  <20020528204350.B74072@FreeBSD.ORG>
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
References:  <20020528195236.A66528@FreeBSD.ORG> <200205290340.g4T3erxr010138@khavrinen.lcs.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
* From Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
> <<On Tue, 28 May 2002 19:52:36 -0700, "J. Mallett" <jmallett@FreeBSD.ORG> 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 <jmallett@FreeBSD.org>                    FreeBSD: The Power To Serve

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020528204350.B74072>