hi Everybody, i copy and paste a line of code bellow as an example:
"#define USB (( USB_TypeDef *) USB_BASE)"
( suppose #define USB_BASE 0x0C000 )
i don't understand the "(( USB_TypeDef *) USB_BASE)"? why the *, the pointer operator, is placed with type inside parenthesis?
thanks, Ras
Addresses are numeric (integer) values to specific memory locations.
But the compiler does not like to use integers for performing memory accesses.
So you need to perform a type cast, where you explicitly informs the compiler "the very specific memory area that starts at this very specific address happens to store data of the following type".
That is the purpose of the type cast ((USB_TypeDef *) USB_BASE)
So the compiler then knows that you have a pointer (storing the integer USB_BASE) that will point to a block of memory of the USB_TypeDef type. And this means that if USB_TypeDef is a struct, then the source code can access the individual fields of this struct and the compiler will produce the required code to access the very specific address of the underlying registers stored within this address range.
This is all very very basic C. So if you aren't comfortable with the use of pointers, then I suggest you spend some time with some good programming tutorials. The C language is very heavily focused around pointers so it isn't something you can avoid learning.
Per Westermark!
thank you very much.
" The first is a type cast - telling the compiler to treat an integer as a pointer to a sepcific data type.
The second is a variable declaration. Telling the compiler to allocate the memory for a single variable USB_BASE that is of type "Pointer to USB_TypeDef"."
these solved my problem; type casting.
( i am learning c programming language within my embedded projects. )
with the best regards,
Rasool