[問題] cast array of int to array of pointer

看板C_and_CPP作者 (我抓得到什麼呢?)時間9年前 (2015/06/02 22:31), 編輯推噓0(0011)
留言11則, 4人參與, 最新討論串1/1
問題(Question): 好奇一件事: 我現在有很多個硬體IO address,想寫成array of pointers去存取它 int * const port_dir[10]={(int*)0x42128005, (int*)0x42128000, (int*)0x42188004, (int*)0x42128001, (int*)0x42188005, (int*)0x42128004,................} 在宣告/定義的時候, 除了上面這樣, 還有什麼方法initialize一堆pointer嗎? 像是 int * const port_dir[10]=(cast?){...} 不過這種還是make pointer from integer 覺得上面這樣寫很... 重複 除了寫成macro這種只是藏起來的方法 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.169.194.43 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1433255494.A.CD2.html

06/02 22:33, , 1F
先說清楚甚麼是重複? 理想的樣式呢?
06/02 22:33, 1F

06/02 22:38, , 2F
不用打那麼多次(int*),只是想想啦,不然用vi插入也是很快
06/02 22:38, 2F

06/02 22:39, , 3F
不知道有沒有好一點的style
06/02 22:39, 3F

06/02 22:40, , 4F
或著說大家如果看到這種code(就算每個address都有註解)
06/02 22:40, 4F

06/02 22:40, , 5F
開個uint的array再cast成int*的array?
06/02 22:40, 5F

06/02 22:40, , 6F
會不會氣到腦充血這樣
06/02 22:40, 6F

06/02 22:41, , 7F
你是不想有 address 還只是不想那麼多 cast ?
06/02 22:41, 7F

06/02 22:42, , 8F
不想這麼多cast
06/02 22:42, 8F

06/02 22:43, , 9F
有辦法不要有address嗎?!
06/02 22:43, 9F

06/02 23:07, , 10F
你心中沒有 address, address 就不在你心中 (阿門)
06/02 23:07, 10F

06/03 16:07, , 11F
Map+Macro如何? http://ideone.com/CYtEy3
06/03 16:07, 11F
文章代碼(AID): #1LRRv6pI (C_and_CPP)