3.21 More about pointers.
+0 +1 +2
|..|3.|12|..
Here are FAT12-related functions in Linux Kernel:
fat12_ent_get(),fat12_ent_put().
Nevertheless, I did as I did because values are better visible and recognizable in byte-level GDB dump,
for the sake of demonstration.
3.20.13 Exercise.
Perhaps, there could be a way to store data in a such way, so getter/setter functions would be faster. If
we would place values in this way:
(Even elements)
+0 +1 +2
|23|1.|..|..
(Odd elements)
+0 +1 +2
|..|.1|23|..
This schema of storing data will allow to eliminate at least one shift operation. As an exercise, you may
rework my C/C++ code in that way and see what compiler will produce.
3.20.14 Summary.
Bit shifts (<
place bit(s) to specific place.
AND operation (&in C/C++,ANDin x86/ARM) is used to drop unneeded bits, also during isolation.
OR operation (|in C/C++,ORin x86/ARM) is used to merge or combine several values into one. One input
value must have zero space at the place where another value has its information-caring bits.
ARM64 has new instructionsUBFM,UFBIZto move specific bits from one register to another.
3.20.15 Conclusion
FAT12ishardlyusedsomewherenowadays, butifyouhavespaceconstraintsandyouhavetostorevalues
limited to 12 bits, you may consider tightly-packed array in the manner it’s done in FAT12 table.
3.21 More about pointers
The way C handles pointers, for example,
was a brilliant innovation; it solved a lot of
problems that we had before in data
structuring and made the programs look
good afterwards.
Donald Knuth, interview (1993)
For those, who still have hard time understanding C/C++ pointers, here are more examples. Some of
them are weird and serves only demonstration purpose: use them in production code only if you really
know what you’re doing.