Re: copy-bit macro

Stephen Williams (steve@icarus.icarus.com)
Tue, 09 Dec 1997 22:51:42 -0800


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

output |= ((input / INPUT_FLAG_FOO) & 1) * OUTPUT_FLAG_FOO;
output |= ((input / INPUT_FLAG_BAR) & 1) * OUTPUT_FLAG_BAR;
output |= ((input / INPUT_FLAG_BAZ) & 1) * OUTPUT_FLAG_BAZ;

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;

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

-- 
Steve Williams
steve@icarus.com
steve@picturel.com

"The woods are lovely, dark and deep. But I have promises to keep, And lines to code before I sleep, And lines to code before I sleep."