Re: copy-bit macro

Rik van Riel (H.H.vanRiel@fys.ruu.nl)
Wed, 10 Dec 1997 18:31:57 +0100 (MET)


On Tue, 9 Dec 1997, Stephen Williams wrote:

the original:
> if (input & INPUT_FLAG_FOO)
> output |= OUTPUT_FLAG_FOO;
> if (input & INPUT_FLAG_BAR)
> output |= OUTPUT_FLAG_BAR
> if (input & INPUT_FLAG_BAZ)
> output |= OUTPUT_FLAG_BAZ

Stephen's (??) versions of the above:
> Seems to me, this specific example can be reduced to
> output |= input & (INPUT_FLAG_FOO|INPUT_FLAG_BAR|INPUT_FLAG_BAZ);
>
> A single bit copy can be:
> output |= input & INPUT_FLAG_FOO;

#define INPUT_FLAG_FOO 0x00000020
#define OUTPUT_FLAG_FOO 0x00002000

now compare the above code fragments :)

> If people are really writing codes like the if statements above, then
> something is wrong. I suspect the example has been stripped down a bit.

the original does something else than your (?) version...

> If not, I think it is better to use the "x |= i & FLAG" if that really
> is the case as yet another macro can be avoided.

What's wrong with macros??? :)

Rik.

--
Send Linux memory-management wishes to me: I'm currently looking
for something to hack...