
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
"Las" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Here is the sample area:
>
> #define P0 ((*(__R volatile unsigned char *)(unsigned char)0x0))
> #define P1 ((*(__R volatile unsigned char *)(unsigned char)0x1))
> #define P2 ((*(__R volatile unsigned char *)(unsigned char)0x2))
> #define P3 ((*(__R volatile unsigned char *)(unsigned char)0x3))
>
> How would you describe what this is or does? If someone could break it
down
> so I could understand what is going on I would be in your debt.
Basically, it's a kludge. (folks in comp.lang.c will undoubtedly point out
that it's not "guaranteed" to work -- esp. P0)
In each case, the constants 0, 1, 2, and 3 are being cast to unsigned char's
(probably out of confusion :-/ ). I believe these (rightmost) casts are
superfluous.
Moving towards the left, each of these constants is then cast to a pointer
to an "unsigned char" -- that being a typical concept of a "generic byte"
The volatile keyword tells the compiler not to optimize away references
to this "item" (since you claim it represents a memory mapped I/O
device, this is "as expected"...)
No comment as to what the "__R" macro does.
The leftmost '*' tells the compiler to dereference this "pointer".
In other words, it evaluates to "the value of the unsigned char
located at the 'address' referenced by this pointer that happens
to have the value ("address") of "0x0", "0x1", etc."
The leftmost token following the #define keyword allows the programmer
to refer to this contortion with a simple mnemonic -- i.e. "P0"
(Port0), etc.
--don
N.B. Incoming mail is not accepted at this email address.
| <-- __Chronological__ --> | <-- __Thread__ --> |