On 2020-10-01 18:55:04 +0200, Alejandro Colomar via Gcc wrote:
> On 2020-10-01 18:38, Michael Kerrisk (man-pages) wrote:
> > > +According to the C language standard,
> > > +a pointer to any object type may be converted to a pointer to
> > > +.I void
> > > +and back.
> > > +POSIX further requires that any pointer,
> > > +including pointers to functions,
> > > +may be converted to a pointer to
> > > +.I void
> > > +and back.
> > I know you are correct about POSIX, but which part of the
> > standard did you find this information in? The only
> > reference that I find in POSIX is the dlsym() spec. Is it
> > covered also somewhere else in the standrd?
[...]
> I've bean searching, and dlsym is the only one:
[...]
> The most explicit paragraph in dlsym is the following:
> 
> [[
> Note that conversion from a void * pointer to a function pointer as in:
> 
> fptr = (int (*)(int))dlsym(handle, "my_function");
> 
> is not defined by the ISO C standard.
> This standard requires this conversion to work correctly
> on conforming implementations.
> ]]

I think that "this conversion" applies only to the dlsym context,
and the conversion isn't defined in general. Imagine that the
void * pointer to function pointer conversion requires the compiler
to generate additional code. The compiler may be able to detect
that dlsym will not be used in some contexts (e.g. because of
always false condition) and do not generate such additional code,
making the conversion to have undefined behavior.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to