在整理退休工程师的代码时,我遇到了一个相当简单的宏,但我的 C 知识不太好。
#define mem32(addr) (*(unsigned long volatile *)(addr))
- 我是否正确地将其称为类型转换指针取消引用?
- 它类型转换addr然后取消引用它?或者反过来呢?这重要吗?
- 顺序对于类型限定符和类型说明符重要吗?我假设(在此之前)类型限定符必须位于类型说明符之前,但事实并非如此
- 语法问题。第二个 * 的用途是什么?
最佳答案
- Am I correctly calling this a type casting pointer dereference?
是的。
- It types casts addr and then derefences it? Or the other way around? Does it matter?
*(unsigned long volatile *)(addr)
正在对 addr
进行类型转换,然后取消引用它。
- Does order matter for type qualifiers and type specifiers?
没有。顺序并不重要。 C11 第 §6.7.2/2 节
[...] the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers. [...]
关于c - 类型转换指针取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34774888/