Even C experts come across problems that require days ofdebugging to fix. This book helps to prevent such problems byshowing how C programmers get themselves into trouble. Each ofthe book's many examples has trapped a professional programmer. In addition to its examples, C Traps and Pitfalls offers adviceon: *avoiding off-by-one errors *understanding and constructing function ...
Even C experts come across problems that require days ofdebugging to fix. This book helps to prevent such problems byshowing how C programmers get themselves into trouble. Each ofthe book's many examples has trapped a professional programmer. In addition to its examples, C Traps and Pitfalls offers adviceon: *avoiding off-by-one errors *understanding and constructing function declarations *understanding the subtle relationship between pointers andarrays Distilled from the author's experience over a decade ofprogramming in C, this book is an ideal resource for anyone,novice or expert, who has ever written a C program. 0201179288B04062001
C has only one-dimensional arrays, and the size of an array must be fixed as a constant at complilation time. The second half of this sentence is not true any more - C99 added support for variable-size arrays.
2019-07-17 12:57:33
C has only one-dimensional arrays, and the size of an array must be fixed as a constant at complilation time.引自 3.1 Pointers and arrays
The second half of this sentence is not true any more - C99 added support for variable-size arrays.
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type. C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.
2013-04-03 11:16:39
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type.
C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.引自 4.4. C Doesn’t Always Cast Actual Parameters
2.1 Understanding Declarations 2.2 Operators Don't Always Have the Precedence You Want if ( (flags & FLAG) != 0 ) r = (h << 4) + 1; Precedence: bind operators; unary operators; binary operators 1. Every logical operator has lower precedence than every relational operator. 2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operat...
2013-04-03 10:20:31
2.1 Understanding Declarations
2.2 Operators Don't Always Have the Precedence You Want
if ( (flags & FLAG) != 0 )
r = (h << 4) + 1;
Precedence: bind operators; unary operators; binary operators
1. Every logical operator has lower precedence than every relational operator.
2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operators.
2.3 Watch Those Semicolons!
Eg: struct foo {
int x;
}
f(){ ... }
There effect of this is to declare that the function f reutrns a struct foo, which is defined as part of this declaration. If the semicolon were present, f would be defined by default as returning an integer.
2.4 The Switch Statement
case SUBTRACT:
opnd2 = -opnd2;
/* no break */
case ADD:
...
2.5 Calling Functions
f(); not f;
2.6 The Dangling else Problem
else is always associated with the closest unmatched if.
1.1 = is not == if ( (x = y) != 0) {...} not if ( x = y ) {...} 1.2 & and | are not && or || 1.3 Multi-character Tokens y = x/*p; y = x / *p; y = x / (*p); 1.4 Exceptions += are mutiple tokens. a + /* strange */ = 1 means the same as a += 1 ->, >> is a single token, >>= is made up of two tokens, not three. 1.5 Strings and Characters In an ASCII implementation, 'a' me...
2013-04-03 10:19:52
1.1 = is not ==
if ( (x = y) != 0) {...} not if ( x = y ) {...}
1.2 & and | are not && or ||
1.3 Multi-character Tokens
y = x/*p; y = x / *p; y = x / (*p);
1.4 Exceptions
+= are mutiple tokens. a + /* strange */ = 1 means the same as a += 1
->, >> is a single token, >>= is made up of two tokens, not three.
1.5 Strings and Characters
In an ASCII implementation, 'a' means exactly the same thing as 0141 or 97.
A string enclosed in double quotes, on the other hand, is a short-hand way of writing a pointer to a nameless array that has been initialized with the characters between the quotes and an extra character whose binary value is zero.
different between 'yes' and "yes":
2.1 Understanding Declarations 2.2 Operators Don't Always Have the Precedence You Want if ( (flags & FLAG) != 0 ) r = (h << 4) + 1; Precedence: bind operators; unary operators; binary operators 1. Every logical operator has lower precedence than every relational operator. 2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operat...
2013-04-03 10:20:31
2.1 Understanding Declarations
2.2 Operators Don't Always Have the Precedence You Want
if ( (flags & FLAG) != 0 )
r = (h << 4) + 1;
Precedence: bind operators; unary operators; binary operators
1. Every logical operator has lower precedence than every relational operator.
2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operators.
2.3 Watch Those Semicolons!
Eg: struct foo {
int x;
}
f(){ ... }
There effect of this is to declare that the function f reutrns a struct foo, which is defined as part of this declaration. If the semicolon were present, f would be defined by default as returning an integer.
2.4 The Switch Statement
case SUBTRACT:
opnd2 = -opnd2;
/* no break */
case ADD:
...
2.5 Calling Functions
f(); not f;
2.6 The Dangling else Problem
else is always associated with the closest unmatched if.
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type. C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.
2013-04-03 11:16:39
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type.
C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.引自 4.4. C Doesn’t Always Cast Actual Parameters
C has only one-dimensional arrays, and the size of an array must be fixed as a constant at complilation time. The second half of this sentence is not true any more - C99 added support for variable-size arrays.
2019-07-17 12:57:33
C has only one-dimensional arrays, and the size of an array must be fixed as a constant at complilation time.引自 3.1 Pointers and arrays
The second half of this sentence is not true any more - C99 added support for variable-size arrays.
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type. C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.
2013-04-03 11:16:39
It is the programmer’s responsibility to ensure that the arguments to a function are of the right type.
C has two simple rules that control conversion of function arguments: (1) integer values shorter than an int are converted to int; (2) floating-point values shorter than a double are converted to double. All other values are left unconverted.引自 4.4. C Doesn’t Always Cast Actual Parameters
2.1 Understanding Declarations 2.2 Operators Don't Always Have the Precedence You Want if ( (flags & FLAG) != 0 ) r = (h << 4) + 1; Precedence: bind operators; unary operators; binary operators 1. Every logical operator has lower precedence than every relational operator. 2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operat...
2013-04-03 10:20:31
2.1 Understanding Declarations
2.2 Operators Don't Always Have the Precedence You Want
if ( (flags & FLAG) != 0 )
r = (h << 4) + 1;
Precedence: bind operators; unary operators; binary operators
1. Every logical operator has lower precedence than every relational operator.
2. The shift operators bind more tightly than the relational operators but less tightly than the arithmetic operators.
2.3 Watch Those Semicolons!
Eg: struct foo {
int x;
}
f(){ ... }
There effect of this is to declare that the function f reutrns a struct foo, which is defined as part of this declaration. If the semicolon were present, f would be defined by default as returning an integer.
2.4 The Switch Statement
case SUBTRACT:
opnd2 = -opnd2;
/* no break */
case ADD:
...
2.5 Calling Functions
f(); not f;
2.6 The Dangling else Problem
else is always associated with the closest unmatched if.
0 有用 Titan_Pascal 2022-01-04 11:44:24
( *(void(*)()) 0)();
0 有用 西晓 2015-01-29 21:52:42
It's a collection of programming mistakes. It's very handy.
0 有用 Reading 2013-02-06 21:01:12
很短的书,但分析到了很多case
0 有用 明扬 2017-11-06 14:47:45
informative yet a bit boring.
0 有用 付业成 2011-02-20 13:29:14
标记已读。
0 有用 Titan_Pascal 2022-01-04 11:44:24
( *(void(*)()) 0)();
0 有用 花狸子 2021-04-07 16:10:23
对于C语言里面的一些比较容易放错的地方,基本上都总结到了这本书里面。如果你想知道C语言为什么会这样而不是你想的那样,那么恭喜你找到了这本书。
0 有用 玉面飞龙 2019-01-01 12:25:58
深入内核和原理
0 有用 明扬 2017-11-06 14:47:45
informative yet a bit boring.
0 有用 曾阿牛 2016-10-28 00:11:02
经典无需多言