1.P127
The main change made by the ANSI standard is to define structure assignment--structures may be copied and assigned to, passed to functions, and returned by functions. This has been supported by most compilers for many years, but the properties are now precisely defined. Automatic structures and arrays may now also be initialized.
这里提到编译器支持结构体和数组自动变量的初始化,难道还有不支持它们初始化的历史?这和支持自动变量类型的赋值有什么区别吗?
P128
A structure can be initialized by following its definition with a list of initializers, each a constant expression.
An automatic structure may also be initialized by assignment or by calling a function that returns a structure of the right type.
-------------------------------------------------
2.P129
Structures may not be compared.
-------------------------------------------------
3.P132
The structure oprerators . and -> , together with () for function calls and [] for subscripts, are at the top of the precedenc hierarchy and thus bind very tightly. for example, given the declaration
struct {
int len;
char *str;
} *p;
then ++p->len
increments len, not p, because the implied parenthesization is ++(p->len).
Parentheses can be used to alter the binding: (++p)->len increments p before accssing len, and (p++)->len increments p afterword.
In the same way , *p->str fetches whatever str points to; *p->str++ increment str after accessing whatever it points to(just like *s++); (*p->str)++ increments whatever str points to; and *p++->str increments p after accessing whatever str points to.
--------------------------------------------------
4.P133
Since the structure keytab contains a constant set of names, it is easiest to make it an external variable(为什么要强调外部变量???) and initialize it once and for all when it is defined.
--------------------------------------------------
5.P135
#define NKEYS (sizeof(keyTab) / sizeof(keyTab[0]))
A sizeof can not be used in #if line, because the preprocessor does not parse type names.But the expression in the #define is not evaluated by the preprocessor, so the code here is legal.
-------------------------------------------------
6.P138
struct key *low, *high, *mid;
The computation of the middle element can no longer be simply
mid = (left + right) / 2;
because the additon of two pointers is illegal.Substraction is legal,however, so
high - low is the number of elements, and thus
mid = low + (high - low) / 2
sets mid to point to the element halfway between low and high.
--------------------------------------------------
7.P138
The problem is that &tab[-1] and &tab[n] are both outside the limits of the array tab. The former is strictly illegal, and it is illegal to dereference the latter. The language definition does guarantee, however, that pointer arithmetic that involoves the first element beyond the eand of an array ( that is, &tab[n]) will work correctly.
In main we wrote
for (p = keytab; p < keytab + NKEYS; P++)
If p is pointer to a structure, arithmetic on p takes into account the size of the structure, so p++ increments p by the correct amount to get the next element of the array of structures, and the test stops the loop at the right time.
---------------------------------------------------
8.P138
Don't assume, however, that the size of a structure is the sum of the size of its members.Because of alignment requirements for different objects, there may be unnamed "holes" in a structure.Thus,for instance, if a char is one byte and an int four bytes,the structure
struct
{
char c;
inti;
};
might well require 8 bytes , not 5. The sizeof operator returns the proper value.
----------------------------------------------------
9.P146
typedef char *String;
typedef void Sigfunc(int); 注意,这里的void不能加上()
typedef struct tnode *Treeptr;
typedef struct tnode
{
char *word;
int count;
Treeptr left;
Treeptr right;
}Treenode;
Notice that the type being declared in a typedef apprears in the position of a variable name, not right after the word typedef.
Syntactically , typedef is like the storage classes extern , static , etc.
We have used capitalized names for typedefs, to make them stand out.
-------------------------------------------------------
10.P146
It must be emphasized that a typedef declaration does not create a new type in any sense, it merely adds a new name for some existing type. Nor are there any new semantics(语义):variables declared this way have exactly the same properties as variables whose declarations are spelled out explicitly. In effect, tyedef is like #define , except that since it inperpreted by the compiler, it can cope with textual subsititutions that are beyond the capablities of the preprocessor.For example,
typedef int (*PFI)(char * ,char *);
creates the type PFI, for "pointer to function (of two char * arguments) returning int", which can be used in contexts like
PFI strcmp, numcmp;
--------------------------------------------------------
11.P147
Unions provided a way to manipulate different konds of data in a sigle area of storate, without embedding any machine-dependent information in the program.(???)
---------------------------------------------------------
12.P147
The usage must be consistent:the type retrieved must be the type most recently stored.
It is the programmer's responsibility to keep track of which type is currently stored in a union, the results are implementation-dependent if something is stored as one type and extracted as another.
---------------------------------------------------------
13.P148
A union may only be initialized with a value of the type of its first member.
---------------------------------------------------------
阅读(900) | 评论(0) | 转发(0) |