作者pttworld (批踢踢世界)
看板C_and_CPP
标题Re: [问题] 关於微控制器中的指标写法
时间Sat Nov 19 21:06:49 2016
※ 引述《goodzey (--)》之铭言:
: 请教大家,在微控制器ARM的STM32Lxx.h有以下指标写法
: #define GPIOB_BASE (0x0c00)
: #define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
: typedef struct
: {
: __IO uint32_t CRL;
: __IO uint32_t CRH;
: __IO uint32_t IDR;
: __IO uint32_t ODR;
: __IO uint32_t BSRR;
: __IO uint32_t BRR;
: __IO uint32_t LCKR;
: } GPIO_TypeDef;
: int main(void)
: {
: GPIOB->CRH &= 0xFFFFFFF0;
: GPIOB->CRH |= 0x00000003;
: }
: 其中的指标写法:
: #define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
: 请问大家,有没有简单的example code可以协助理解这种写法?
: 我找了很多网路资料都没有多说
: 在正规C语言中这种写法的关键字是什麽?查得到C语言正规教材吗?
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
6.3.2.3 Pointers
An integer may be converted to any pointer type.
Except as previously specified,
the result is implementation-defined,
might not be correctly aligned,
might not point to an entity of the referenced type,
and might be a trap representation.56)
The mapping functions for converting a pointer to an integer or
an integer to a pointer are intended to
be consistent with the addressing structure of the execution environment.
previously type是讨论null pointer,
56)的addressing已经说得很清楚了。
关键字是cast。
: 谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 115.43.36.13
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1479560812.A.F34.html
1F:推 goodzey: 谢谢 11/20 08:52