The C Programming Language [Second Edition]


   The range of both int and float depends onthe machine you are using;(p.9)
   If an arithmetic operator has integer operands, an integer operation is performed. If an arithmetic operator has one floating-point operand nad one integer operand, however, the integer will be converted to floating point before the operation is done.(p.12)
   long integers are at least 32 bits.
   ...
   printf uses %f for both float and double;(p.18)
   newcomers to C occasionally write = when they mean ==. ... the result is usually a legal expression, so you will get no warning.(p.19)
   Don't begin variable names with underscore, however, since library routines often use such names.(p.35)
   The character constant '\0' represents the character with value zero, ... (p.38)
   External and static variables are initialized to zero by default. Automatic variables for which there is no explicit initializer have undefined (i.e., garbage) values.(p.40)
   The % operatot cannot be applied to float or double.(p.41)
   Expressions that don't make sense, like using a float as a subscript, are disallowed.(p.42)
   The language does not specify whether variables of type char are signed or unsigned quantities.(p.43)
   The cast operator has the same high precedence as other unary operators, ... (p.45)
   The increment and decrement operators can only be applied to variables; an expression like (i+j)++ is illegal.(p46)
   The shift operators ... operand by the number ... must be nonnegative. ... Right shifting a signed quantity will fill with sign bits ... on some machines and with 0-bits ... on others.(p.49)
   And an assignment operator may even help a compiler to produce efficient code.(p.51)
   If expr2 and expr3 are of different types, the type of the result is determined by the conversion rules discussed earlier in this chapter.(p.52)
   A pair of expressions separated by a comma is evaluated left to right, the type and value of the result are the type and value of the right operand.(p.62)
   The continue statement applies only to loops, not to switch.(p.65)
   The scope of a label is the entire function.(p.66)
   If the function takes arguments, declare them; if it takes no arguments, use void.(p.73)
   There must be only one definition of an external variable among all the files that make up the source program; other files may contain extern declarations to access it. ... Array sizes must be specified with the definition, but are optional with an extern declaration.
   Initialization of an external variable goes only with the definition.(p.81) 

    In C, a two-dimensional array is really a one-dimensional array, each of whose elements is an array.(p.112)

   If a two-dimensional array is to be passed to a function, the parameter declaration in the function must include the number of columns.(p.112)

   By convention, argv[0] is the name by which the program was invoked, so argc is at least 1.  ………….  The first optional argument is argv[1] and the last is argv[argc-1]; additionally, the standard requires that argv[argc] be a null pointer.(p.115)

   Any Pointer can be cast to void * and back again withou loss of information, … (p.120)

   A structure member or tag and an ordinary (i.e., non-menber) variable can have the same name without conflict, since they can always be distinguished by context.(p.128)

   C provides a compile-time unary operator called sizeof that can be used to compute the size of any object.

   …

   (Strictly, sizeof produces an unsiged integer value whose type, size_t, is defined in the header .)(p.135)

   The language definition does guarantee, however, that pointer arithmetic that involves the first element beyond the end of an array (that is, &tab[n]) will work correctly.(p.138)

   Don’t assume, however, that the size of a structure is the sum of the sizes of its members. Because of alignment requirements for different objects, there may be unnamed “holes” in a structure.(p.138)

   Notice that the type being declared in a typedef appears in the position of a variable name, not right after the word typedef. Syntacticlly, typedef is like the storage calsses extern, static, etc.(p.146)

   Almost everything about fields is implementation-dependent. …… Fields need not be named; unnamed fields (a colon and width only) are used for padding.   

   …

   Fields are assigned left to right on some machines and right to left on others. …… Fields may be declared only as ints; for portability, specify signed or unsigned explicitly. They are not arrays, and they do not have addresses, so the & operator cannot be applied to them.(p.150)

   Input and output facilityes are not part of the C language itself,(p.151)
   If the character after the % is not a conversion specification, the behavior is undefined.(p.154)
  
printf(s); /* FAILS if s contains % */ (p.155)

   The declaration ... can only appear at the end of an argument list.
   When a C program is started, the operating system environment is responsible for opening three files and providing file pointers for them. These files are the standard input, the standard output, the standard error; the corresponding file pointers are called stdin, stdout, stderr, and are declared in <stdio.h>.(p.161)
   Output written on stderr normally appears on the screen even if the standard output is redirected.(p.163)
   Confusingly, gets deletes the terminal '\n', and puts adds it.(p.164)
   The characters /* introduce a comment, which terminates with the characters */. Comments do not nest, and they do not occur within string or character literals.(p.192)
   A constant in this extended set is written with a preceding L, for example L'x', and is called a wide character constant.(p.193)
   A string has type "array of characters" and storage class static and is initialized with the given characters. Whether identical string literals are distinct is implementaion-defined, and the behavior of a program that attempts to alter a string literal is undefined.
   ...
   As with character constants, string literals in an extended charcter set are written with a preceding L, as in L"...". ... Concatenation of ordinary and wide string literals in undefined.(p.194) 
   When a value of floating type is converted to integral type, the fractional part is discarded; if the resulting value cannot be represented in the integral type, the behavior is undefined. In particular, the result of converting negative floating values to unsigned integral types is not specified.(p.197)
   The presence of parentheses does not affect whether the expression is an lvalue.
   ...
   The term argument is used for an expression passed by a function call; the term parameter is used for an input object (or its identifier) received by a function definition, or described in a funciton declaration.(p.201~202)
   The sizeof ... operand is either an expression, which is not evaluated, (p.204)
   Otherwise, it is always true that (a/b)*b + a%b is equal to a. If both operands are non-negative, then the remainder is non-negative and smaller than the divisor; if not, it is guaranteed only tha the absolute value of the remainder is smaller than the absolute value of the divisor.(p.205)
   The shift operators << and >> ... The result is undefined if the right operand is negative, or greater than or equal to the number of bits in the left expression's type.(p.206) 
   Less latitude is allowed for the integral constant expressions after #if; sizeof expression, enumeration constants, and casts are not permitted.(p.209)
   At most one storage class specifier may be given in a declaration.
   ...
   If the type-specifier is missing from a declaration, it is taken to be int.(p.211) 
   The members of a structure have addresses increasing in the order of their declarations. A non-field member of a structure is aligned at an addressing boundary depending on its type; therefore, there may be unnamed holes in a structure.(p.213)
   Qualifiers following * apply to pointer itself, rather than to the object to which the pointer points.(p.216)
   a multi-dimensional array, only the first dimension may be missing.(p.217)
   The initializer ... is either an expression, or a list of initializers nested in braces. A list may end with a comma, a nicety for neat formatting.(p.218~219)
   A static object not explicitly initialized is initialized as if it (or its members) were assigned the constant 0. The initial value of an automatic object not explicitly initialized is undefined.
   ...
 Unnamed bit-field members are ignored, and are not initialized. If there are fewer initializers in the list than members of the structure, the trailing members are initialized with 0.(p.219)
   Declarations whose storage class specifier is typedef do not declare objects; instead they define identifiers that name types.(p.221)
   Initialization of automatic objects is performed each time the block is entered at the top, and proceeds in the order of the declarators. If a jump into the block is executed, these initializations are not performed.(p.223)
   An external declaration for an object is a definition if it has an initializer.(p.227)
   

   This replacment occurs before any other processing.

??=  #     ??(  [    ??<  {

  
??/  \     ??)  ]    ??>  }

  
??'  ^     ??!  |    ??-  ~

 No other such replacements occur.(p.229)

   Lines tha end with the backslash character \ are folded by deleting the backslash and the following newline character. This occurs before division into tokens.(p.229)
   ...
   the preprocessor leading and trailing white space around the token sequence is discarded.
   ...
   A line of the form
           # define identifier( identifier-list ) token-sequence
   where there is no space between the first idenifier and the (, is a macro definition with parameters given by the identifier list.(p.229)
   It is not erroneous to apply #undef to an unknown identifier.
   ...
   if an occurrence of a parameter in the replacement token sequence is immediately preceded by #, string quotes (") are placed around the corresponding parameter, and then both the # and the parameter identifier are replaced by the quoted argument. A \ character is inserted before each " or \ charater that appears surrounding, or inside, a string literal or charater constant in the argument.
   ...
   In both kinds of macro, the replacement token sequence is repeatedly rescanned for more defined identifiers. However, once a given identifier has been replaced in a given expansion, it is not replaced if it turns up again during rescanning; instead it is left unchanged.
   Even if the final value of a macro expansion begins with #, it is not taken to be a preprocessing directive.(p.230) 
   A control line of the form
              # include <filename>
causes the replacement of that line by the entire contents of the file filename.(p.231)
   Each of the directives (if-line, elif-line, else-line, and #endif) appears alone on a line.
   ...
   The constant expression in #if and #elif is restricted: it must be integral, and may not contain sizeof, a cast, or an enumeration constant.(p.232) 
   freopen is normally used to change the files associated with stdin, stdout, or stderr.
   ...
   fclose flushes any unwritten data for stream, discards any unread buffered input, frees any automatically allocated buffer, then close the stream.(p.242) 
posted @ 2011-03-24 17:14  walfud  阅读(702)  评论(0编辑  收藏  举报