Re: [問題] 關於微控制器中的指標寫法

看板C_and_CPP作者 (批踢踢世界)時間9年前 (2016/11/19 21:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《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://www.ptt.cc/bbs/C_and_CPP/M.1479560812.A.F34.html

11/20 08:52, , 1F
謝謝
11/20 08:52, 1F
文章代碼(AID): #1OC4viyq (C_and_CPP)
文章代碼(AID): #1OC4viyq (C_and_CPP)