> > For example, if you work on code related to SCSI or filesytems or otherwise connected with
disks, you're expected to recognise that (bytes >> 9) converts from a byte count to a sector
count, since sectors are 512 bytes.
> However, a well-crafted macro BYTES2SECTORS(bytes) would give me a clue, and the magic
numbers and operations on them would live in the definition of the macro, so you've got one
place to maintain the conversion and it's clear to us noobs what it's related to.
But in the context of the kernel, hiding things in a BYTES2SECTORS macro can be downright
dangerous. What types does it handle for input and output? Does it sleep or have any locking
requirements? If I pass an expression, do I have to worry about side effects if it gets
evaluated twice? How does it behave if bytes is not a multiple of one sector?
Is it talking about the canonical 512-byte defintion of a sector or the actual 2048 byte
sectors used on CD-ROMs?
"bytes >> 9" is absolutely clear. I see instantly that it handles integer types and matches
the signedness. It is free from side effects and fast. I know that the answer is rounded
down to the nearest whole sector. Sectors are 512 bytes.
I don't see why you would want to hide all of that information from a developer. Your version
is only simpler at a quick glance to a casual observer, not someone who actually has to deal
with the code and what the statement actually does.