This is an embedded block of code looking at a register on an STM32 processor. The following compiles without error:
Code:
#include <stdint.h>
#define RCC_BASE_ADDR 0x40023800U
int main(void)
{
uint32_t *p;
p = (uint32_t *)RCC_BASE_ADDR;
/* Loop forever */
for(;;);
}
The following compiles with error:
Code:
#include <stdint.h>
#define RCC_BASE_ADDR 0x40023800U
int main(void)
{
uint32_t *p;
p = (uint32_t *)(&RCC_BASE_ADDR);
/* Loop forever */
for(;;);
}
What I am failing to understand is I thought that a pointer in this case p should be pointing to an address (aka use of &). Why is the second block of code not correct? Or for that matter why does the first block of code work without the &?
Thank you