Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro
From: Linus Torvalds
Date: Sun Nov 26 2006 - 17:24:58 EST
On Sun, 26 Nov 2006, Roland Dreier wrote:
> > +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
> > +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
> Fine by me, but it loses the extra (typeof(x)) cast that Al wanted to
> make sure that the result of ALIGN() is not wider than x.
Well, since "mask" is now made to be of the same type as "x", every
sub-expression actually has the same type, modulo the normal C behaviour
of "expand to at least "int".
So arguably, the result is _more_ like a normal C operation this way.
Type-wise, the "ALIGN()" macro acts like any other C operation (ie if you
feed it an "unsigned char", the end result is an "int" due to the normal C
type widening that happens for all C operations).
But I don't care horribly much. Al may have some other reasons to _not_
want the normal C type expansion to happen (ie maybe he does something
unnatural with sparse ;)
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/