Jolley, Thomas P wrote:
Not sure I should jump into this but it's hard to stay out.
Yeah, it's one of those issues. Hopefully Robert will chime in soon. My
guess is he'll probably elect to propagate the osgUtil::Optimizer design
pattern. It'd be fun to place bets. :-)
Perhaps the second argument type in osgUtil::Optimizer::optimize should be
changed from unsigned int to OptimizationOptions. You can still use the enum
and avoid the confusion of whether it is signed or unsigned.
Have you actually used this in software that you've written? How did you
OR the bit values together?
Code of the following form will not compile:
osgUtil::Optimizer::OptimizationOptions flags( 0 );
flags |= osgUtil::Optimizer::SHARE_DUPLICATE_STATE;
flags |= osgUtil::Optimizer::MERGE_GEODES;
And if the 2nd param to optimize were OptimizationOptions, the following
code would not compile:
optimize( node,
osgUtil::Optimizer::SHARE_DUPLICATE_STATE |
osgUtil::Optimizer::MERGE_GEODES );
"|" and "|=" are not defined for enum types. So I'm a little confused by
this suggestion.
An unsigned int will work just as well as a signed int for bitmask. All the
bitwise logical operations work the same. Testing for == 0 and != 0 work the
same. Shift left works the same. The only things that don't work the same are
shift right and some arithmetic operations you wouldn't want to do anyway.
I hear you, but this is not a reason to make them signed rather than
unsigned. It is just a statement that they are equivalent in this respect.
I can't imagine a case where I would ever want to treat a bit
or a bitmask as a signed value. I can imagine testing (mask
!= 0), but I can never imagine needing to test for (mask < 0)
or (mask > 0). Knowing whether a bit or mask is negative or
positive conveys no useful information.
(mask < 0) would mean the most significant bit is true (but only if it is
signed).
You could say the same for testing an unsigned int against 13. I can't imaging
testing for (mask < 13) or (mask > 13). This also conveys no useful
information for a bitmask.
If you want to test for the highest bit, you should AND the mask against
the variable denoting the highest bit value. There is no need to make
bits and masks signed to enable this sort of test, other than for
purposes of code obfuscation.
Regarding "(mask < 13)", testing a bitmask against 0 is meaningful.
Testing it against a (non-zero) hardcoded constant value is code
obfuscation, regardless of whether you use signed or unsigned values.
-Paul
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org