Hi Paul, Not sure I should jump into this but it's hard to stay out.
> -----Original Message----- > I think we disagree on what, exactly, we disagree on. :-) > > Unless I'm mistaken. we all agree that bit values should have > the same data type as the bitmask variables meant to contain them. 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. > > Wojciech Lewandowski wrote: > > However, I will keep my opinion that when one decides to > use enums for > bit combinations, > > This is where we begin to disagree, because, given the > information that enums are always ints, then it's a mistake > to use them as bit values. (I admit I'm guilty of propagating > this mistake by following the design pattern precedent in > osgUtil::Optimizer, without thinking about it too > much.) 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. > > Rather than change bitmask variables to int to "match" the > enum type (and I use the term "match" loosely here, because, > IMO, an enum and an int are still conceptually different > types), a better solution would be to Leave the bitmask > variable as unsigned int, and change the enums to static > const unsigned int. Use the enum type instead. It gives you added protection from setting bits that aren't defined. > > 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. ---- Tom Jolley _______________________________________________ osg-submissions mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
