COLE,GLENN (Non-HP-SantaClara,ex2) ([log in to unmask]) wrote:
: Walter Murray writes:
: > If you want to use a cast to force an increment operation to act
: > on all 64 bits of a long pointer, the following should do the
: > trick:
: > (*(long long *)&fcp)++
: If THAT doesn't scare people away from learning C.... ;)
It's really pretty straightforward.
fcp Start with the original 64-bit pointer.
&fcp Generate a pointer to it.
(long long *)&fcp Convert this new pointer to a pointer to a
64-bit integer.
*(long long *)&fcp Take the object that this pointer points to
(which is actually the original 64-bit pointer).
(*(long long *)&fcp)++ Increment it.
I think this is a fairly common idiom in C. It can often be used to
avoid having to use a union. The compiler sees what you're trying to
do and doesn't generate a bunch of unnecessary code. Other than the
loads and stores to transfer the long pointer between memory and
registers, this example generates only three instructions.
Walter