简体   繁体   English

对使用C中的指针的宏感到困惑

[英]Confused about macros using pointers in C

I want to understand this bit of code 我想了解这段代码

#define GET(p) (*(unsigned int*) (p)) 

I learned about pointers but I can't figure out what the statement above means. 我了解了指针,但是我无法弄清楚上面的语句意味着什么。 When I use GET(ptr), am I getting the value at the address ptr points to or the address that ptr contains? 当我使用GET(ptr)时,我是在指向ptr的地址还是指向ptr包含的地址处获取值?

It means the following. 这意味着以下内容。

  1. Cast the pointer p to the type unsigned int* . 将指针p强制转换为unsigned int*类型。
  2. De-reference the pointer to get the value at that address. 取消引用指针以获取该地址的值。

Another way of putting it is that the macro gets the value of the unsigned int at the address specified by p . 另一种放置方法是,宏在p指定的地址处获取unsigned int的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM