lol*_*f64 2 c pointers c-preprocessor
我在网站上找到了这个片段:
#define DISPLAY_CR (*(volatile unsigned int *) 0x4000000)
DISPLAY_CR = somevalue;
Run Code Online (Sandbox Code Playgroud)
应该将DISPLAY_CR描述为指向地址0x4000000的易失性无符号int指针
我不明白的原因是:
额外的括号是宏中的标准做法.宏以复制和粘贴的方式扩展,因此没有括号,优先级可能会根据上下文而改变.
忽略额外的括号,您的代码扩展为:
*(volatile unsigned int *) 0x4000000 = somevalue;
Run Code Online (Sandbox Code Playgroud)
这相当于:
volatile unsigned int *p = 0x4000000; // Treat this as the address of a volatile unsigned int
*p = somevalue; // Write to that address
Run Code Online (Sandbox Code Playgroud)
希望应该更清楚.