Reputation: 35
What is the meaning of
*((volatile UINT32*)(a)) ?
in C langauage?
Give me some example.
Upvotes: 0
Views: 2643
Reputation: 399949
It dereferences a
, after first casting it to type "pointer to volatile UINT32
".
There are way more parentheses than needed, it would be better written as:
*(volatile UINT32 *) a
That does the same thing. You'd expect there to be some more code here, of course, either a write:
*(volatile UINT32 *) a = 4711;
that writes 4711
to the address contained in a
, making sure (due to the volatile
) that the write is not optimized out even if it can seem pointless from the compiler's point of view.
Or a read:
const UINT32 packetCounter = *(volatile UINT32 *) a;
which reads the current value at the address in a
, and stores it in a local constant variable called packetCounter
. This is how it would look if a
is the address of some I/O register. Again due to the volatile
, the read must happen, it cannot be optimized out or cached even though it might seem pointless to the compiler. This is common with I/O registers.
Upvotes: 3