Hi all, As a followup to CBFalconer's contribution and the resulting discussion: It is always possible to find a hair in the soup. ;-)
To clarify some issues: The example was taken from an article in the embedded systems programming magazine (Programmer's test) which I find very enlightening because it reflects 99% of the C language related support questions I get to handle every day.
The 'registers' I was mentioning were meant to be so called Special Function Registers of peripherals on an MCU.
It is common procedure (as with many toolchains I know) to implement header files for MCU derivatives this way. This goes for GNU as well as vendor specific tools alike.
Before posting I have tested the example with a little testcase.
The example:
unsigned int *ptr; ptr = (unsigned int *)0x67a9;
*ptr = 0xaa55;
*(int * const)(0x67a9) = 0xaa55;
should better have been posted like:
/******* memio.c ********/ volatile unsigned int* SFR_IO_addr = (volatile unsigned int* )0x1500;
unsigned int *ptr;
void foo(void) { ptr = (unsigned int *)0x67a9; /* assign address */ * ptr = 0xaa55; /* store datum into address */ *(int * const)(0x67a9) = 0xaa55; /*The expression is legal but somewhat cyptic.*/
while(*SFR_IO_addr==0) { ; /* wait forever while SFR_IO_addr = 0 */ } }
void main(void) { foo(); }
/******* EOF memio.c ********/ So we do not run into the 'uninitialized pointer' issue CBFalconer mentioned.
I hope this clears the fog a bit.
with kind regards /jan