作者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/m.aspx?n=bbs/C_and_CPP/M.1479560812.A.F34.html
1F:推 goodzey: 謝謝 11/20 08:52