#define PORTC *(unsigned char volatile *)(0x1003)
#define DDRC *(unsigned char volatile *)(0x1007)
So I’ve been trying to read some stuff about embedded C. Initially I thought this macro was a pointer-to-pointer type but then I soon assumed the last star is actually a dereference rather than a type-cast, am I correct? Dereferencing to the location 0x1003/0x1007.
It is used like: PORTC = <some hex value>
Question is what makes this different from a pointer type-cast? Is there some sort of ‘provision’ in the C specifications? Or am I just an idiot…
Also I don’t quite know how to phrase this and so I couldn’t do a quick search first…
It’s just the way the C grammar is defined.
To be a cast, the expression needs parenthesis:
(type)sub-expressioncastssub-expressionto typetype.Your example,
*(unsigned char volatile *)(0x1003)is composed of 2 sub-expressions:*(unsigned char volatile *)(0x1003)The cast is composed of the type inside
()and a value.So, the whole expression is interpreted as a pointer, then de-referenced to set the memory area pointed to.