[問題] function prototype scope
各位好,小弟最近在複習C How to Program 6/E,看到了function prototype scope這邊
圖:https://imgur.com/a/FvvlT
中文說明大致上為:用在function prototype裡面的參數有function prototype scope,然
後接著說:其實這個參數是不用打上識別字的,只需要型別就行,就算打上去的話,也會被
compiler忽略,所以如果在程式裡面宣告了跟參數一樣的識別字也不會有問題。
坦白講,小弟覺得有講跟沒講一樣,所以上網google了一下這篇討論串(PS:我沒學過C++)
討論串:
https://stackoverflow.com/questions/24393273/example-of-function-prototype-scope
看了一下發現其實不是很懂,故發文上來請教前輩們。
其中一開始的內文寫道:In a function declaration, or in any function declarator..
想請問,這邊的declarator是指什麼東西?第一次看到這個名詞,上網查好像是C++才有?
接著,The best answer說明了: The compiler will issue an error for the second
parameter a because its name coincides with the name of the first parameter.
問題: Compiler不是會忽略parameter的name嗎?為什麼還會issue an error?
接著The best answer又說: The same name is defined twice in the same scope.
問題: 我聽起來的直覺是,function prototyp scope的範圍就只是在function prototype
裡面而已,是這樣嗎?
接著,The best answer又說明了一個範例,並說明第一個parameter name把struct name
給藏起來了,所以struct name是使用詳盡的結構名稱定義的。
問題: 為什麼第一個參數會把第二個參數給藏起來?對Compiler來說,他們應該都是不存在
的。
謝謝前輩們看完小魯的發言~感恩感恩
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.26.157
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1512705349.A.842.html
※ 編輯: zzss2003 (60.248.26.157), 12/08/2017 11:56:08
推
12/08 12:25,
8年前
, 1F
12/08 12:25, 1F
→
12/08 12:27,
8年前
, 2F
12/08 12:27, 2F
→
12/08 12:28,
8年前
, 3F
12/08 12:28, 3F
→
12/08 12:29,
8年前
, 4F
12/08 12:29, 4F
→
12/08 12:29,
8年前
, 5F
12/08 12:29, 5F
→
12/08 12:30,
8年前
, 6F
12/08 12:30, 6F
→
12/08 12:31,
8年前
, 7F
12/08 12:31, 7F
推
12/08 13:25,
8年前
, 8F
12/08 13:25, 8F
→
12/08 13:27,
8年前
, 9F
12/08 13:27, 9F
→
12/08 13:28,
8年前
, 10F
12/08 13:28, 10F
想請問一下,這段是什麼意思@@看不太懂:(
推
12/08 13:31,
8年前
, 11F
12/08 13:31, 11F
→
12/08 13:32,
8年前
, 12F
12/08 13:32, 12F
推
12/08 13:35,
8年前
, 13F
12/08 13:35, 13F
→
12/08 13:36,
8年前
, 14F
12/08 13:36, 14F
→
12/08 13:37,
8年前
, 15F
12/08 13:37, 15F
→
12/08 14:37,
8年前
, 16F
12/08 14:37, 16F
話說我找不到C89的standard C,唯一找到的版本的字寫得很模糊...看得很不舒服
之前有網友說要找大陸的網址,但是我還是找不到QQ
※ 編輯: zzss2003 (60.248.26.157), 12/08/2017 16:03:42
推
12/08 16:24,
8年前
, 17F
12/08 16:24, 17F
→
12/08 16:24,
8年前
, 18F
12/08 16:24, 18F
→
12/08 16:59,
8年前
, 19F
12/08 16:59, 19F
→
12/12 13:36,
8年前
, 20F
12/12 13:36, 20F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章