小弟最近在拜读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: 为什么这个方法会相当马虎? 哪边马虎?