It makes 0x100 the address of a pointer?it's a cast operation?
Yes. '0x100' alone is just an integer value. Putting the cast
'(unsigned long *)' in front of it tells the compiler that
while it looks like a number it's actually to be treated as
a pointer.
i don't understand first *.... if i write ( volatile unsigned long * )
0x100 = 50, what i obtain? If i think it linke a pointer, shouldn't be
*address=50?
I guess Ian already has made the point clear - the '*' in front of
a pointer tells that you want to change what the pointer is poin-
ting to (and not the pointers value itself, which you couldn't
do here anyway since the pointer value is the fixed value 0x100),
so it's, as you already suspect, just like
* address = 50;
Adding another set of (redundant) parentheses may make it clearer:
* ( ( volatile unsigned long * ) 0x100 ) = 50;
The '( ( volatile unsigned long * ) 0x100 )' bit is exactly the
same type 'address' has in the line above (if 'address' is a
pointer to volatile unsigned long).
Just a final bit of pedantry: what you do here invokes undefined
behaviour. The memory at 0x100 is not memory you obtained by e.g.
calling malloc() etc. or is the address of one of your variables.
So in "normal situations" you wouldn't be allowed to write to it
or read from it. But here it looks as if your system documentation
is giving you a special permission by defining what's going to
happen when you write to that address (e.g. setting up some system
timer). So, while it's undefined behaviour from a C point of view
(since the C language can't define what happens on all systems
when you write to address 0x100), your system documentation defines
it and you thus may do so. Of course, as a result your program will
rather likely not work on any other system - on some it could crash
and on others writing to 0x100 might format your hard disk or start
the self-destruction sequence;-)
Regards, Jens