Casting in C/C++

OP #1171027
Rate this post
• ▲ useful
▼ not useful
Hi Guys
I have a piece of code for flashing an LED using AT91R40807 on an
AT91EB40 evaluation board.I'm having difficult understanding the
following portion using casting

 #define led_mask = (led1|led2|led3)
 void flashled(int color) {

  *(unsigned int*)(0xFFFOO10) = led_mask
  *(unsigned int*)(0xFFFOO00) = led_mask
  *(unsigned int*)(0xFFFOO34) = led_mask
  ....continues

my question is why were these memory addresses chosen "IN PARTICUALR"
when masking.As far as I know they just represent the location of the
output enable register,enable register and clear output data register
respectively.Probably you can tell me what actually happens with casting
used like this.

G
#1171028
Rate this post
• ▲ useful
▼ not useful
I am not sure if I understand exactly what it is you are asking; but the
addresses are first cast to pointer types and then derefenced you modify
their content.

The cast is necessary to provide the absolute address with a 'type',
i.e. it says this address points to an 'int'. Without providing type in
this way, the compiler would not know how many bits to write.

Clifford

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.