What does the second pointer after u8 mean in this code?
I suppose you speak about the second "*"
u8*
is the type "pointer to an u8"
(*(volatile u8*) 0x3A)
adding () it is like
(*((volatile u8*) 0x3A))
so 0x3A
is considered as an address of an u8 (u8*
) and the first "*" dereference it so (*((volatile u8*) 0x3A))
try to return the u8 at the address 0x3A
(it will produces a segmentation fault if 0x3A is not a valid address) or on a left side of an assignment try to write at the address 0x3A
For instance defining u8 as a char and replacing 0x3A by the address of a global var :
#include <stdio.h>
#define DDRA (*(volatile u8 *) &A)
typedef char u8;
int A = 'a';
int main()
{
printf("%c\n", DDRA);
DDRA = 'b';
printf("%c\n", DDRA);
return 0;
}
Compilation and execution :
pi@raspberrypi:/tmp $ gcc -pedantic -Wextra -Wall c.c
pi@raspberrypi:/tmp $ ./a.out
a
b