lkml.org 
[lkml]   [1997]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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...


\
 
 \ /
  Last update: 2005-03-22 13:40    [W:0.036 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site