> You either need to add a comment, or use a define. bytes >> 9 without a clarifier is something that should never be in production-quality code. Magic numbers should never be in code without a clear explanation what they mean. If you don't want a macro that can hide things, write something like bytes >> SECTOR_SHIFT. If one doesn't want to hide things, hide it inside "SECTOR_SHIFT"? I'm sorry, I remain unconvinced. Using ">> 9" is essentially a comment saying "I'm converting this to a 512-byte sector count". It's such a fundamentally basic operation that anyone working with filesystem or disk code would understand it immediately. Abstracting common constants is most useful when they might change, and they're just arbitrary to begin with -- HZ for example. Or things that actually have no real meaning, like magic numbers that identify a filesystem. For a number that has a real, well-known meaning, and for which changing would involve huge logic changes in the code, I think macros like that are just extra levels of obfuscation.
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds