I should better explain what I am trying to do with this C code.
... On an intel based system ... Microsoft give this example in C
on how to access the data in the buffer ...
FAT32ClusEntryVal = (*((unsigned long *) &Buffer[ThisFATEntOffset]));
Others have explained the cast, but just to reiterate, a cast
-- which is just a type-name enclosed in parentheses, such as
(unsigned long *)
-- means "take a value, and convert it to a new (and possibly very
different) value, as if by assignment to a temporary variable whose
type is given by the cast". The conversion happens just as for
ordinary assignment, except that if there is something inherently
suspicious -- or even seriously wrong -- with that conversion, the
compiler should do its best to do it anyway without complaint.
As such, casts are quite powerful and should be used with care.
Think of them as being like nitroglycerine: in small quantities,
it can even save your life (cardiac patients use it to avoid
heart attacks), and when treated with care, it can be very handy,
but it can also blow your fingertips right off.
Having converted the pointer value to a new one of type
"unsigned long *", the unary "*" at the front of the whole
expression follows the new pointer, retrieving an "unsigned long"
from that address -- or crashing, or doing something else bad,
if you are not on an Intel x86 and the address is not aligned.
Of course, the result is machine-dependent, because FAT32
entries are written as four little-endian octets, regardless of
the underlying machine's representation for an "unsigned long",
which brings me to the thing no one else has mentioned yet in
the part of this thread that made it to my news server....
Since a FAT32 value is always between 0x00000000 and 0x0fffffff,
the type "unsigned long" is guaranteed to be big enough to hold
it. Unfortunately, it might well be *too* big. So this
expression is not only machine-endianness-dependent, but also
"machine uses 32-bit long"-dependent. Some C compilers for 64-bit
architectures (including x86-64) are now starting to have 64-bit
"long"s. Thus, even restricting oneself to Intel CPUs, this
expression is rather inadvisable. Building up a 32-bit value
from four 8-bit octets, using shift-and-mask code, will work
on machines other than the Intel. (The built-up value can be
safely stored in any "unsigned long", because all C implementations
are required to have a ULONG_MAX that is at least 0xffffffff,
though it may be larger, as on those 64-bit systems.)