HP3000-L Archives

August 2000, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Walter Murray <[log in to unmask]>
Reply To:
Walter Murray <[log in to unmask]>
Date:
Thu, 24 Aug 2000 20:36:18 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (27 lines)
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

ATOM RSS1 RSS2