Copyright (慣C) 2015, 2017 宅色夫
==直播錄影==
Jonathan Adamczewski 貼出經典著作《The C Programming Language》,然後評註說:
"C++: The Good Parts"
C++ 可以美得令人不知所措 [source]
從一則笑話談起
葉秉哲博士的推文:「==溯源能力==是很重要的,才不會被狀似革新,實則舊瓶裝新酒或跨領域借用的『新觀念』所迷惑」
規格書 (PDF) 搜尋 "object",共出現 735 處
從第一手資料學習:大文豪寫作都不免要查字典,庸俗的軟體開發者如我們,難道不需要翻閱語言規格書嗎?難道不需要搞懂術語定義和規範嗎?
&
不要都念成 and,涉及指標操作的時候,要讀為 "address of"
C99 [3.14] object
region of data storage in the execution environment, the contents of which can represent values
在 C 語言的物件就指在執行時期,==資料==儲存的區域,可以明確表示數值的內容
很多人誤認在 C 語言程式中,(int) 7 和 (float) 7.0 是等價的,其實以資料表示的角度來看,這兩者截然不同,前者對應到二進位的 "111",而後者以 IEEE 754 表示則大異於 "111"
A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.
關鍵描述!規範
void *
和char *
彼此可互換的表示法
void *memcpy(void *dest, const void *src, size_t n);
C99 規格書的解說就比很多書本清楚,何必捨近求遠呢?
float *
has type ""pointer to float’". Its type category is pointer, not a floating type. The const-qualified version of this type is designated as float - const
whereas the type designated as "const float *
is not a qualified type — its type is ""pointer to const qualified float’" and is a pointer to a qualified type.struct tag (*[5])(float)
has type "array of pointer to function returning struct tag’". The array has length five and the function has a single parameter of type float. Its type category is array.Understand more about C 提及若干肇因於不同的 C 語言標準,而使得程式碼行為不同的案例
安裝 cdecl
程式,可以幫你產生 C 程式的宣告。
$ sudo apt-get install cdecl
使用案例
$ cdecl
cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char
會得到以下輸出:
char *(*(*a[])())()
把前述 C99 規格的描述帶入,可得:
cdecl> declare array of pointer to function returning struct tag
struct tag (*var[])()
如果你沒辦法用英文來解說 C 程式的宣告,通常表示你不理解!
cdecl
可以解釋 C 程式宣告的意義,比方說:
cdecl> explain char *(*fptab[])(int)
declare fptab as array of pointer to function (int) returning pointer to char