gpt4 book ai didi

c - 将结构定义的地址存储到指针中时是否会创建结构实例?

转载 作者:太空宇宙 更新时间:2023-11-04 06:57:22 25 4
gpt4 key购买 nike

在我的微 Controller 类(class)中,我们正在为 SAMD20J18 微 Controller 编写嵌入式 C 语言。

我们程序的开头包含以下两行代码:

Port *ports = PORT_INSTS; 
PortGroup *porA = &(ports->Group[0]);

第二行对我来说意味着 Port 结构的一个实例存在,因为它的 Group 成员正在被访问。但是,类(class)手册指出 PORT_INSTSPort 结构定义(如下所示)的基地址,而不是它的一个实例。是否通过将结构定义的地址存储在指针 ports 中来创建结构 Port 的实例? PORT_INSTS 地址指向结构 Port 的现有实例对我来说更有意义。是我错了还是说明书错了?

这是手册的相关部分:

manual

最佳答案

The second line implies to me that an instance of the Port struct exists since its Group member is being accessed. However, the course manual states that PORT_INSTS is the base address of the Port struct definition (shown below), rather than an instance of it.

两者都是。该结构的目的是在现有的 MCU 硬件寄存器之上创建一个抽象层。寄存器已经存在于硬件中,从给定的基地址开始。这就是为什么您不必分配任何东西。

关于c - 将结构定义的地址存储到指针中时是否会创建结构实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42602244/

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