It seems that I have missed the discussion that produced this wording, and this
may not be the right time or place to contribute my two cents, but here it goes
anyway...
> (0000129) msbrown (manager) - 2009-06-29 02:27
> http://austingroupbugs.net/view.php?id=74#c129
> ----------------------------------------------------------------------
> After the sentence ending on line 18890, add the following:
>
> If a pointer to an object or incomplete type is converted to a pointer
> to void and then to a pointer to a function type the behavior
> is undefined.
I don't think this is right. In C, an assignment or an initialization is
specified to always performs a conversion -- even a conversion from a type to
the same type is still considered a conversion. Doesn't that mean that the
value returned by dlsym() cannot be assigned to anything without invoking
undefined behaviour?
Wasn't the goal here to say that even though a dlsym() call with the name of a
function symbol returns a void* pointer that can be safely converted to a
pointer to function, the conversion of any other data pointers to function
pointers is still undefined behaviour? (Also, since POSIX does not promise
that the void* pointer points to any object, trying to do pretty much anything
else with that pointer is undefined behaviour too.)
> If a pointer to a function type is converted to
> a pointer to void and then to a pointer to an object or an incomplete
> type the behaviour is undefined.
Doesn't that imply that it's safe to convert a pointer to function to a pointer
to void, as long as the pointer is not subsequently converted to some other
pointer type? Is it meant to imply that it's OK for a portable POSIX
application to take the address of an arbitrary function and convert it to
void* and back? That's much more than C promises, and more than dlsym() needs
(unless there's a requirement that it must be possible to implement dlsym() in
portable C).
|