This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix aliasing violation tst-rec-dlopen


On Tue, Dec 15, 2015 at 11:40:55AM -0500, Carlos O'Donell wrote:
> On 12/15/2015 10:30 AM, Zack Weinberg wrote:
> > POSIX assumes an architecture where object and function pointers
> > are interconvertible, and ...
> > 
> >>               The 2013 Technical Corrigendum to POSIX.1-2008 (a.k.a.
> >>               POSIX.1-2013) improved matters by requiring that conforming
> >>               implementations support casting 'void *' to a function pointer.
> > 
> > ... that was the correct thing for them to do, and the right way to write
> > this program is just to use a cast.
> 
> I wrote the code in question, and I did what was historically considered
> best practice, old habits die hard.
> 
> If new compilers complain then we should absolutely switch to and encourage
> correct casting of function pointers to their appropriate types. It's the
> only thing that makes sense.

If you want to avoid both you can use a temp object of type void* and
memcpy to the actual object with function pointer type. I don't
particularly recommend that though. The value conversion is perfectly
fine and it was only a mistake in POSIX (which has since been fixed)
that caused the aliasing-violation monstrosity to be introduced.

Rich


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]