小弟最近在拜讀Axel-Tobias Schreiner的Object-oriented Programming in ANSI-C,
殊不知看不太懂作者想要表達的想法與觀念,故想上網請教前輩們。
附上pdf網址:https://www.cs.rit.edu/~ats/books/ooc.pdf
在PDF第7頁,"Alternatively, we can define a data type as a set of values plus
operations to work with them."
data type可以定義為一組數值+上與數值的運算,不太懂這句話想要表達的含意是什麼(註
:我只會C,不會C++)
對我來說data type就是最基本的int, char,double與float,其餘像是array, struct,
union都是最基本的延伸的變化型。
接著在下列的這句話"Typically, the values are what a computer can represent, and
the operations more or less reflect the available hardware instructions. int in
ANSI-C does not do too well in this respect: the set of values may vary between
machines, and operations like arithmetic right shift may behave differently."
第二句看不懂,operation體現出可使用的硬體指令?為什麼ANSI-C的int在這方面做得不太
好?是哪方面?
接著,"More complicated examples do not fare much better. Typically we would
define an element of a linear list as a structure"
作者說明更複雜的data type進展的也不是很好,並舉例了一個例子:
typedef struct node {
struct node * next;
... information ...
} node;
and for the operations we specify function headers like
node * head (node * elt, const node * tail);
作者說明,這個方法相當馬虎,好的原則應該是要隱藏data item的representation且只
declare possible manipulations.
問題1: 什麼是 linear list? 為什麼這個struct是linear list的一種?
問題2: head應該是指向一個函式的指標吧?
問題3: 所以operation不是指+ - * /這類的?
問題4: 這個例子的representation of data item是那些東西?
問題5: only declare possible manipulation是指什麼意思?
問題6: 為什麼這個方法會相當馬虎? 哪邊馬虎?