Linux-kernel mailing list archive 1997-49,: Re: copy-bit macro

# Re: copy-bit macro

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

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: teunis: "3.6G ide harddrive probs with fdisk"
- Previous message: Rik van Riel: "Re: ctime"
- In reply to: Stephen Williams: "Re: copy-bit macro"
- Next in thread: Ian Collier: "Re: copy-bit macro"

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...

- Next message: teunis: "3.6G ide harddrive probs with fdisk"
- Previous message: Rik van Riel: "Re: ctime"
- In reply to: Stephen Williams: "Re: copy-bit macro"
- Next in thread: Ian Collier: "Re: copy-bit macro"