Subject: Re: typeof (Re: CVS commit: src)
To: None <tech-kern@NetBSD.org, tech-userlevel@NetBSD.org>
From: David Young <email@example.com>
Date: 09/03/2006 16:59:06
On Sat, Sep 02, 2006 at 02:32:03PM +0200, Joerg Sonnenberger wrote:
> On Sat, Sep 02, 2006 at 01:40:01AM -0500, 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:
> > > > >
> > > > > Make the __BIT and __BITS macros "widthless," as best I can, by
> > > > > changing their type to uintmax_t from uint32_t. XXX The manual
> > > > > page lags this change by a bit.
> > > > >
> > > > > Define __PRIxBIT and __PRIxBITS printf(3) format strings.
> > > >
> > > > is it ok to use typeof here?
> > >
> > > Almost certainly not since the header files gets built into tools.
> > Please suggest an alternative.
> Take a look at math.h, esp. __fpmacro_unary_floating.
__fpmacro_unary_floating copes with different-sized arguments, but that is
a different problem than the one I need to solve. I want for the "return"
type of __BIT() and/or __SHIFTOUT()/__SHIFTIN() to change depending on
the width of the mask. I've tried this macro, but it always evaluates
to a uintmax_t, which is about what I'd expect:
#define __CAST(__x, __v) \
((sizeof(__x) < sizeof(uintmax_t)) \
? ((sizeof(__x) < sizeof(uint64_t)) \
? ((sizeof(__x) < sizeof(uint32_t)) \
? ((sizeof(__x) < sizeof(uint16_t)) \
? (uint8_t)(__v) \
: (uint16_t)(__v)) \
: (uint32_t)(__v)) \
: (uint64_t)(__v)) \
David Young OJC Technologies
firstname.lastname@example.org Urbana, IL * (217) 278-3933