|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v11 3/9] xen: introduce DECLARE_BOUNDS
On Wed, 6 Mar 2019, Jan Beulich wrote:
> > +static inline ptrdiff_t name ## _diff(const type s1[],
> > \
> > + const struct abstract_ ## name s2[])
> > \
> > +{
> > \
> > + BUILD_BUG_ON(alignof(*s1) != alignof(*s2));
> > \
> > + return (ptrdiff_t)((uintptr_t)s2 - (uintptr_t)s1) /
> > \
> > + (ptrdiff_t)sizeof(*s1);
> > \
> > +}
> >
>
> I had specifically asked for this to simply call _bytediff, to limit
> redundancy and in particular the total number of casts.
>
> > +static inline ptrdiff_t name ## _bytediff(const type s1[],
> > \
> > + const struct abstract_ ## name
> > s2[])\
> > +{
> > \
> > + BUILD_BUG_ON(alignof(*s1) != alignof(*s2));
> > \
> > + return (ptrdiff_t)((uintptr_t)s2 - (uintptr_t)s1);
> > \
> > +}
>
> What's the value of the intermediate casting to uintptr_t? Why not
> cast to ptrdiff_t right away?
uintptr_t is the integer type corresponding to a pointer, so we should
use uintptr_t first. ptrdiff_t is the difference type so we should cast
to it afterwards. Specifically, uintptr_t is unsigned and ptrdiff_t is
signed. So I don't think it would be correct to do:
return (ptrdiff_t)((ptrdiff_t)s2 - (ptrdiff_t)s1);
Or am I missing your point?
I'll address all the other comments.
> I also don't think the BUILD_BUG_ON() is helpful in this latter case.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |