溪边树

象一棵树,栽在溪水旁。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Common Programming Errors -- chapter6

Posted on 2010-03-31 20:22  溪边树  阅读(415)  评论(12编辑  收藏  举报

6.1 Declaring method parameters of the same type as double x, y instead of double x, double y is a syntax error. An explicit type is required for each each parameter in the parameter list.

6.2 Compilation errors occur if the function prototype, function header and function calls do not all agree in the number, type and order of arguments and parameters and in the return type.

6.3 If a function is defined before it is invoked, then the function's definition also serveas the function's prototype, so a separate prototype is unnecessary. If a function is invoked before it is defined, and that function does not have a function prototype, a compilation error occurs.

6.4 It is a compilation error if two functions in the same scope have the same signature but different return types.

6.5 Coverting from a higher data type in the promotion hierarchy to a lower type, or between signed and unsigned, can corrupt the data value, causing a loss of information.

6.6 It is a compilation error if the arguments in a function call do not match the number and types of the parameters declared in the corresponding function prototype. It is also an error if the number of arguments in the call matches, but the arguments cannot be implicitly converted to the expected types.

6.7 Accidentally using the same name for an identifier in an inner block that is used for an identifier in an outer block, when in fact the programmer wants the identifier in the outer block to be active for the duration of the inner block, is normally a logic error.

6.8 C++ programs do not compile unless function prototypes are provided for every function or each function is defined before it is called.

6.9 Because reference parameters are mentioned only by name in the body of the called function, the programmer might inadvertently treat reference parameters as pass-by-value parameters. This can cause unexpected side effects if the original copies of the variables are changed by the function.

6.10 Not initializing a reference variable when it is declared is a compilation error, unless the declaration is part of a function's parameter list. Reference parameters are initialized when the function in which they are declared is called .

6.11 Attempting to reassign a previously declared reference to be an alias to another variable is a logic error. The value of the other variable is simply assigned to the variable for which the reference is already an alias.