gpt4 book ai didi

C语言 : how to interpret this #define?

转载 作者:行者123 更新时间:2023-12-01 12:35:41 24 4
gpt4 key购买 nike

我在网站上找到了这个片段:

#define DISPLAY_CR  (*(volatile unsigned int *) 0x4000000) 
DISPLAY_CR = somevalue;

应该将 DISPLAY_CR 描述为一个指向地址 0x4000000 的 volatile unsigned int 指针

我不明白的是为什么:

  • 双括号叠瓦 ?
  • 两颗星使用(为什么两颗星而不是只有一颗?)

最佳答案

额外的括号是宏中的标准做法。宏以复制和粘贴的方式扩展,因此没有括号,precedence可能会根据上下文进行更改。

忽略额外的括号,您的代码扩展为:

*(volatile unsigned int *) 0x4000000 = somevalue;

相当于:

volatile unsigned int *p = 0x4000000; // Treat this as the address of a volatile unsigned int
*p = somevalue; // Write to that address

希望这应该更清楚。

关于C语言 : how to interpret this #define?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9261771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com