[openib-general] [PATCH] Avoid truncating to 'long' in ALIGN() macro

Linus Torvalds torvalds at osdl.org
Sun Nov 26 14:20:10 PST 2006



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 ;)

			Linus




More information about the general mailing list