[prev in list] [next in list] [prev in thread] [next in thread]
List: freebsd-hackers
Subject: Re: sizeof(function pointer)
From: Nathan Whitehorn <nwhitehorn () freebsd ! org>
Date: 2011-05-31 23:41:53
Message-ID: 4DE57CC1.6000105 () freebsd ! org
[Download RAW message or body]
On 05/31/11 18:18, Warner Losh wrote:
> On May 31, 2011, at 5:07 PM, mdf@freebsd.org wrote:
>
> > I am looking into potentially MFC'ing r212367 and related, that adds
> > drains to sbufs. The reason for MFC is that several pieces of new
> > code in CURRENT are using the drain functionality and it would make
> > MFCing those changes much easier.
> >
> > The problem is that r212367 added a pointer to a drain function in the
> > sbuf (it replaced a pointer to void). The C standard doesn't
> > guarantee that a void * and a function pointer have the same size,
> > though its true on amd64, i386 and I believe PPC. What I'm wondering
> > is, though not guaranteed by the standard, is it *practically* true
> > that sizeof(void *) == sizeof(int(*)(void)), such that an MFC won't
> > break binary compatibility for any supported architecture? (The
> > standard does guarantee, though not in words, that all function
> > pointers have the same size, since it guarantees that pointers to
> > functions can be cast to other pointers to functions and back without
> > changing the value).
> >
> > Another possibility is to malloc a blob that is sizeof(int(*)(void))
> > and store that in a renamed s_unused; this is a bit messier but
> > guaranteed to work. I'd just rather the code be an MCF instead of a
> > partial re-write.
> It is the same on MIPS too for all three ABIs that we support (and all ABIs that I \
> know about). It is true on ARM as well.
> Usually it is different only on segmented architectures like 16-bit x86.
It is also true on ARM, PPC, PPC64, and ia64, which I just tested. I
think you're safe.
-Nathan
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic