Kaz Kylheku wrote:
> On Tue, 16 Apr 2002, Donn Terry wrote:
> > 1) The size of either type of pointer could be the larger. On a
> > segment/offset machine,
> > function pointers might have to be, say, 48 bits for a 16 bit segment
> > and a 32 bit offset,
> > but for data pointers a segment can be assumed and they need only be
> > 32 bits.
>
> In this model, the void * (and, consequently, char *) pointers can be
> 48 bits wide so that they can transparently record a function pointer
> value. Other data pointers can be represented in 32 bits.
On machines that want pointers to be aligned, this would make char and
void pointers twice as big as they need to be, just for the sake of
allowing them to store a function pointer occasionally -- even though
trying to store a function pointer in a void pointer is officially
undefined behaviour in C. I don't think it would be easy to convince
many compiler vendors (and users!) that they really need this waste of
memory, and the added complexity of having to handle two different
representations of data pointers, just because the POSIX folks didn't
think of this problem when they were defining dlsym()...
Let me repeat what I think is the easiest way out of this: just change
the return of dlsym() to an implementation-defined typedef called, for
instance, dlsym_t. On all platforms capable of supporting today's
dlsym(), dlsym_t can be defined as void*, and no real code changes will
be required (even though conversions from dlsym_t to anything else will
now require an explicit cast, at least in theory). On our hypothetical
platform with 48-bit function pointers and 32-bit data pointers, dlsym_t
can be defined as a function pointer or perhaps a 64-bit integer, which
will make dlsym() possible to implement without unreasonable overhead or
significant modifications to compilers.
...
> In neither model do you need special treatment of dlsym by the
> compiler; the work can be done in dlsym so that the pointer conversion
> performed by the program does the right thing.
But you do need special treatment for your unnaturally large void and
char pointers.
|