Re: [語法] 關於 typedef 簡化 多維Arrays 的指標...

看板C_and_CPP (C/C++)作者 (我愛阿蓉)時間15年前 (2009/10/15 04:21), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串4/4 (看更多)
※ 引述《archon (三腳貓的把戲)》之銘言: : typedef int* intP; : const intP p2; : 又有點兒套不好,他是 int* const p2 的意思... : typedef 後頭接的型態 (int *),就是用 intP 宣告會產生的型態, :  而使用 typedef 後的自訂型態來宣告,還可以透過 const 或 * 再進一步修飾, :  經由多個例子的歸納,我似乎可以感應到 typedef 各種用法的意思, :  但是它究竟實際上的運作全貌,卻還是很模糊... : #define、macro,跟 typedef 之間決定性的不同,到底該怎麼說清楚呢 /"\a? 剛好我之前有再研究這種怪東西 紀錄了一下 typedef char *cstring; 以下宣告的cstr是什麼型別? extern const cstring cstr; 你可以試著想想看 答案是extern char * const cstr; 我覺得你就把修飾字 整個 一起套進去 const cstr整個帶進去就會出來答案了.... 真的做一下解釋 extern const cstring cstr; 等同於extern cstring const cstr; 這要先知道 從右邊讀到左邊 cstr 是一個const的 XXX(cstring type) 好 ~ cstring是什麼呢? 我用了typedef 定義他是char* 所以就變成 cstr是一個const的指標(*) 指向char 再翻成語言 char* const cstr; 最後extern再修飾這整塊 結果答案是 extern char* const cstr; 一般人可能會猜 是extern const char * cstr; 我覺得這樣解釋你可以接受嘛@@ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.207.187 ※ 編輯: QQ29 來自: 140.113.207.187 (10/15 04:21) ※ 編輯: QQ29 來自: 140.113.207.187 (10/15 04:25)

10/15 04:38, , 1F
(筆記筆記) ~大感謝!!!
10/15 04:38, 1F

10/15 04:39, , 2F
另外,我找到另一個很精彩的網頁,分享給大家~~~
10/15 04:39, 2F

10/15 04:41, , 4F
typedef function 的部分,值得一看... A_A
10/15 04:41, 4F
文章代碼(AID): #1ArZB3fJ (C_and_CPP)
文章代碼(AID): #1ArZB3fJ (C_and_CPP)