推 wtchen: 感謝,在C11 standard是這樣定義: 04/16 19:03
→ wtchen: 6.3.2.3-3: An integer constant expression with the 04/16 19:03
→ wtchen: value 0, or such an expression cast to type void *, 04/16 19:04
→ wtchen: is called a null pointer constant. 04/16 19:04
→ wtchen: If a null pointer constant is converted to a pointer 04/16 19:05
→ wtchen: type, the resulting pointer, called a null pointer, 04/16 19:05
→ wtchen: is guaranteed to compare unequal to a pointer to any 04/16 19:06
→ wtchen: object or function. 04/16 19:06
→ wtchen: 所以我們不能說NULL是0,這是有問題的。至於要怎麼說 04/16 19:06
→ wtchen: 怎麼解釋給新手聽,還要再想想 Orz 04/16 19:07
→ Frozenmouse: 還有要怎麼解釋 if (ptr) { //blah } 這種寫法 XD 04/16 19:18
→ Caesar08: 樓上那個只要把pointer的值取出來就好 04/16 20:14
→ Caesar08: 就跟int i=/*number*/; if(i)一樣 04/16 20:15
→ Frozenmouse: 上面那條是((void*)0) -> 空指標,反過來一樣嗎@@ 04/16 20:31
→ Caesar08: 只要是指標,就會儲存一個記憶體位置 04/16 20:37
→ Caesar08: 直接讀取指標(不加*),就是讀取記憶體位置 04/16 20:38
→ Caesar08: 現在void pointer指向0,所以if(ptr)就是if(0) 04/16 20:38
→ Frozenmouse: 我的意思是有沒有規定像你說的那樣把 null pointer 04/16 20:48
→ Frozenmouse: 轉回數值確定是 0 XD 04/16 20:48
→ Frozenmouse: 還是我哪裡有誤解… 04/16 20:48
→ Caesar08: The macro NULL is an implementation-defined C++ null 04/16 22:03
→ Caesar08: pointer constant in this International Standard 04/16 22:03
→ Caesar08: N4582, 18.2, 3 04/16 22:03
→ Caesar08: 但我覺得C++11都出了,為何不用nullptr? 04/16 22:05
→ Caesar08: 直接警告新手,使用nullptr而不是0或NULL 04/16 22:05
推 wtchen: 可是C11沒有nullptr.... 04/16 22:11
→ Caesar08: ... 還好我都是寫C++而不是C 04/16 22:14
→ Frozenmouse: 感謝樓上m(_ _)m 04/16 22:17
推 wtchen: 錯字改掉了,至於NULL那邊要怎麼改寫還要想 QQ 04/16 22:18
→ Caesar08: 那C與C++可能要分開了,現在nullptr就出問題了 04/16 22:22
推 wtchen: 我不反對分開,但是要有人寫C++的部份阿 04/16 22:33
→ Caesar08: 只針對13誡,提供C++方面的幫助?(C++要注意太多了) 04/16 22:37
推 wtchen: 也行,再看看怎麼補充。 04/16 22:39
推 wtchen: 其實我覺得13誡可能不夠要再加... 04/16 22:40
→ Frozenmouse: 照其他條那樣 C++ 用補述的呢? 04/16 22:40
→ Frozenmouse: 我指 nullptr 那邊XD 04/16 22:40
推 wtchen: 也是個好方法,C++就勞煩各位幫忙(板工現在忙C的部份) 04/16 22:41
→ Caesar08: 已經有多位大師都在幫忙寫這文件,應該不用質疑正確性吧 04/16 22:41
→ Frozenmouse: 那個連結看到 editors 直接跪了 04/16 22:41
推 wtchen: C的NULL是null pointer constant (空指標常數?) 04/17 02:03
→ Frozenmouse: 直覺上應該是,而且常被定義為 ((void*)0) 04/17 02:08
→ Frozenmouse: ((void*)0)符合你引的C11規範裡的 null ptr const 04/17 02:09
推 wtchen: 繁體中文翻譯成空指標常數沒錯吧?話說該怎麼跟新手解釋.. 04/17 02:16
推 wtchen: 看來真的該新增一條解釋NULL,'\0',0,nullptr的關係 04/17 02:17
推 wtchen: 有人可以幫忙寫嗎?要寫得讓新手了解...嗯... 04/17 02:18
推 wtchen: 不過想想好像沒特殊必要,NULL跟0搞不清楚應該不會 04/17 02:34
→ wtchen: 毀滅地球.... 04/17 02:34
→ Frozenmouse: '\0'==0應該沒問題,先以推廣不要直接把0當null ptr 04/17 03:57
→ Frozenmouse: 為開始如何? 04/17 03:57
→ Frozenmouse: 單純「凡指標必使用NULL / nullptr」這樣 04/17 03:58
→ Frozenmouse: 詳細怎麼補述還得再想想… 04/17 03:59
推 wtchen: 目前先把3跟6的0改成NULL,至於怎麼敘述nullptr再想想 04/17 17:22
推 wtchen: 對了誡3的gets()應該要換掉,不是安全的函式 04/17 17:24
推 dreamnook: 朝聖推XD 04/20 10:01
推 Yshuan: 用德文念就沒問題了(亂入 04/20 17:12