rhXX wrote On 06/18/07 12:13,:
> hi all,
>
> i want to define a group of consts for bits
>
> #define BIT0 (1 << 0)
> #define BIT1 (1 << 1)
> ...
> #define BITi (1 << i)
>
> is it a way to do it more elegant? or at least to put "i" as parameter
> of other macro?
>
> how i can do some like this???
>
> #define BITX(i) #define BIT##i (1 << i)
You cannot: A macro cannot generate a preprocessor
directive, even if the expansion resembles one.
Even if you could, what help would it be? Instead
of the group of #defines above, you'd have
#define BITX(i) ...something magical...
BITX(0)
BITX(1)
...
BITX(i)
That is, you'd need one *more* line than you already have.
Since the names of your macros are so descriptive

why not just use
#define BIT(i) (1 << (i)) /* maybe 1u? 1uL? 1uLL? */
.... and write BIT(0), BIT(2) instead of BIT0, BIT2?
--