lkml.org 
[lkml]   [2006]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Avoid truncating to 'long' in ALIGN() macro


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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-11-18 23:46    [W:0.544 / U:1.584 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site