Subject: Re: typeof (Re: CVS commit: src)
To: None <,>
From: Alan Barrett <>
List: tech-kern
Date: 09/02/2006 13:48:54
Referring to this code added in revision 1.61 of sys/cdefs.h (slightly

#define	__LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
#define	__SHIFTOUT(__x, __mask)	\
	((typeof(__x))(((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)))
#define	__SHIFTIN(__x, __mask) \
	((typeof(__x))((__x) * __LOWEST_SET_BIT(__mask)))
#define	__SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))

On Sat, 02 Sep 2006, David Young wrote:
> On Sat, Sep 02, 2006 at 12:09:19AM +0100, David Laight wrote:
> > On Fri, Sep 01, 2006 at 09:01:06AM +0900, YAMAMOTO Takashi wrote:
> > > is it ok to use typeof here?
> > Almost certainly not since the header files gets built into tools.
> Please suggest an alternative.

Why do you need to cast at all?  As far as I can see, the right thing
would happen without any casts.  OK, if the inputs are narrower than
int (e.g. unsigned char), and there's no cast, then the result will be
(signed) int, but is that a problem?  What other bad effects am I missing?

--apb (Alan Barrett)