This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/2 v4] libc-internal.h: add ALIGN helper macros
- From: Rasmus Villemoes <rv at rasmusvillemoes dot dk>
- To: libc-alpha at sourceware dot org
- Date: Tue, 04 Jun 2013 10:49:00 +0000
- Subject: Re: [PATCH 1/2 v4] libc-internal.h: add ALIGN helper macros
- References: <1369327649-906-1-git-send-email-vapier at gentoo dot org> <1370070444-911-1-git-send-email-vapier at gentoo dot org> <20130603191205 dot 21F8C2C060 at topped-with-meat dot com> <201306032305 dot 58361 dot vapier at gentoo dot org>
Mike Frysinger <vapier@gentoo.org> writes:
> On Monday 03 June 2013 15:12:05 Roland McGrath wrote:
>> I think we should be using inlines rather than macros any time we don't
>> have a strong reason to use macros.
>
> generally we don't do caps inlines though ? and using inlines means we now
> have to deal with types. the current one works with any size and does the
> right thing. if i wrote an inline, i'd have to pick a type (size_t? int?
> long? uint64_t? uintmax_t?) and then there'd be ugliness with signed vs
> unsigned, implicit casts, implicit truncation, overhead with casting up to
> larger than natural types (like 64bit on a 32bit system), etc...
I'm afraid one would have to deal with types anyway, as recently seen
in the kernel http://lwn.net/Articles/548336/.
>
>> > +/* Align a value by rounding down to closest size.
>> > + e.g. Using size of 4096, we get this behavior:
>> > + {4095, 4096, 4097} = {0, 4096, 4096}. */
>> > +#define ALIGN_DOWN(base, size) ((base) & ~((size) - 1))
This won't DTRT if base is a 64-bit type and size is an unsigned
32-bit type.
--
Rasmus Villemoes
<http://rasmusvillemoes.dk/>