*(< type> *)(< constant>)是什么意思?

编程入门 行业动态 更新时间:2024-10-25 10:30:05
本文介绍了*(< type> *)(< constant>)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近遇到了以下C代码:

I recently came across the following C-code:

*(STRUCT_T*)(0xC6)

STRUCT_T 是 typedef ed结构。有人可以解释这是什么意思?

STRUCT_T is a typedefed structure. Can someone explain what this means?

我的猜测: STRUCT_T * 投射地址 0xC6 到结构指针,然后 * 检索存储在地址 0xC6

My guess: STRUCT_T* casts the address 0xC6 to a structure pointer and * then retrieves the value (struct) stored at the address 0xC6?

推荐答案

是的,你是正确的,但我想,这个问题需要一个更详细的答案为什么

Yes, you're correct but I guess, this question needs a little more elaborated answer for why we are doing this.

首先,让我们来看一下 * 运算符。它取消引用它是基于操作数的类型的操作数。以非常简单的语言详细说明

To start with, let's see what is done by the unary * operator. It dereferences it's operand based on the type of the operand. To elaborate in very simple terms,

  • * ptr c> ptr 的类型 char * 将读取 sizeof(char) ie,1从 ptr
  • * ptr $ c> ptr 的类型 int * 将读取 sizeof(int)从 ptr
  • 开始的4字节数据(在32位系统上)
  • *ptr, when ptr is of type char * will read sizeof(char) i.e., 1 bytes of data starting from ptr
  • *ptr, when ptr is of type int * will read sizeof(int) i.e., 4 bytes of data (on 32 bit system) starting from ptr

,说 *(STRUCT_T *)(0xC6),我们正在执行

  • 将指针(地址) 0xC6 作为指向 STRUCT_T 的指针。
  • dereference相同,以获取 STRUCT_T 的值。
  • treat the pointer (address) 0xC6 as a pointer to type STRUCT_T.
  • dereference the same to get the value of type STRUCT_T.

更多推荐

*(< type> *)(< constant>)是什么意思?

本文发布于:2023-11-09 06:09:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lt   amp   type   constant   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!