Le 31/10/11 11:37, Nick Keighley a écrit :
This book is excellent:-
http://en.wikipedia.org/wiki/The_C_Programming_Language
Unfortunately many on-line tutorials are very poor.
Maybe but that tutorial is really bad.
When explaining the control flow statements it would be nice to
mention (at least) break and continue... longjmp() should be mentioned
too.
The level of that tutorial is really bad, mostly cut/paste from
some man pages, without detailed examples, etc.
The tutorial I wrote tries to improve the quality of the material
presented but will never be mentioned in this group. To give an idea
of the scope of my work here is the table of contents:
1 Introduction to C
1.1 Why learn C?
1.2 Program organization
1.3 Hello
Program input 14
What are "function parameters"?
Console mode programs and windows programs
1.4 An overview of the compilation process
1.4.1 The run time environment
We wrote the program first
We compiled our design
Run time
1.5 An overview of the standard libraries
The "stdheaders.h" header
1.5.1 Passing arguments to a program
Implementation details
1.6 Iteration constructs
1.6.1 for
1.6.2 while
1.6.3 do
1.6.4 break and continue
1.7 Types
1.7.1 What is a type?
1.7.2 Types classification
1.7.3 Integer types
1.7.4 Floating types
1.7.5 Compatible types
1.7.6 Incomplete types
1.7.7 Qualified types
1.7.8 Casting
1.7.9 The basic types
1.8 Declarations and definitions
1.2 Standard type sizes in lcc-win
1.3 Increased precision numbers in lcc-win
1.4 Type sizes for lcc-win 64 bits
1.5 Minimum size of standard types
1.8.1 Variable declaration
1.8.2 Function declarations
1.8.3 Function definitions
1.8.4 Scope of identifiers
1.8.5 Linkage and duration of objects
1.8.6 Variable definition
1.8.7 Statement syntax
1.9 Errors and warnings
1.10 Input and output
1.6 File operations
1.10.1 Predefined devices
1.10.2 The typical sequence of operations
1.10.3 Examples
1.10.4 Other input/output functions
The current position
1.10.5 File buffering
Error conditions
1.11 Commenting the source code
1.11.1 Describing a function
1.11.2 Describing a file
1.12 An overview of the whole language
1.12.1 Statements
1.12.2 Declarations
1.12.3 Pre-processor
1.12.4 Control-flow
1.12.5 Extensions of lcc-win
2 A closer view
2.1 Identifiers.
2.1.1 Identifier scope and linkage
2.2 Constants
2.2.1 Evaluation of constants
Constant expressions
2.2.2 Integer constants
2.2.3 Floating constants
2.2.4 Character string constants
2.2.5 Character abbreviations
2.3 Arrays
2.3.1 Variable length arrays.
2.3.2 Array initialization
2.3.3 Compound literals
2.4 Function calls
2.4.1 Prototypes.
2.4.2 Functions with variable number of arguments.
Implementation details
2.4.3 stdcall
2.4.4 Inline
2.5 Assignment.
2.6 The four operations
2.6.1 Integer division
2.6.2 Overflow
2.6.3 Postfix
2.7 Conditional operator
2.8 Register
2.8.1 Should we use the register keyword?
2.9 Sizeof
2.10 Enum
2.10.1 Const.
Implementation details
2.11 Goto
2.12 Break and continue statements
2.13 Return
2.13.1 Two types of return statements
2.13.2 Returning a structure
2.13.3 Never return a pointer to a local variable
2.13.4 Unsigned
2.14 Null statements
2.15 Switch statement
2.16 Logical operators
2.17 Bitwise operators
2.18 Shift operators
2.19 Address-of operator
2.20 Indirection
2.21 Sequential expressions
2.22 Casts
2.22.1 When to use casts
2.22.2 When not to use casts
2.23 Selection
2.24 Predefined identifiers
2.25 Precedence of the different operators.
2.26 The printf family
2.1 The parts of a printf specification
2.2 Prototypes for the main functions of the printf family
2.26.1 Conversions
2.3 The conversion flags
2.26.2 The minimum field width
2.26.3 The precision
2.26.4 The conversions
2.26.5 Scanning values
2.4 The size specification
2.6 scanf directives
2.27 Pointers
2.27.1 Operations with pointers
2.27.2 Addition or subtraction of a displacement: pointer arithmetic
2.27.3 Subtraction
2.27.4 Relational operators
2.27.5 Null pointers
2.27.6 Pointers and arrays
2.27.7 Assigning a value to a pointer
2.27.8 References
2.27.9 Why pointers?
2.28 setjmp and longjmp
2.28.1 General usage
2.28.2 Register variables and longjmp
2.29 Time and date functions
3 Simple programs
3.1 strchr
3.1.1 How can strchr fail?
3.2 strlen
3.2.1 A straightforward implementation
3.2.2 An implementation by D. E. Knuth
3.2.3 How can strlen fail?
3.3 ispowerOfTwo
3.3.1 How can this program fail?
3.3.2 Write ispowerOfTwo without any loops
3.4 signum
3.5 strlwr
3.5.1 How can this program fail?
3.6 paste
3.6.1 How can this program fail?.
3.7 Using arrays and sorting
3.7.1 How to sort arrays
3.7.2 Other qsort applications
3.7.3 Quicksort problems
3.8 Counting words
3.8.1 The organization of the table
3.8.2 Memory organization
3.8.3 Displaying the results
3.8.4 Code review
3.9 Hexdump
3.9.1 Analysis
3.9.2 Exercises
3.10 Text processing
3.10.1 Detailed view
main
ProcessChar
ReadLongComment and ReadLineComment
ReadCharConstant
OutputStrings
3.10.2 Analysis
3.10.3 Exercises:
3.11 Using containers
4 Structures and unions
4.1 Structures
4.1.1 Structure size
4.1.2 Using the pragma pack feature
4.1.3 Structure packing in other environments
Gcc
Hewlett Packard
IBM
Comeau computing C
Microsoft
4.1.4 Bit fields
4.2 Unions
4.3 Using structures
4.4 Basic data structures
4.4.1 Lists
4.4.2 Hash tables
4.4.3 The container library of lcc-win
4.5 Fine points of structure use
5 Simple programs using structures
5.1 Reversing a linked list
5.1.1 Discussion
An improvement
Preconditions
6 A closer look at the pre-processor
6.1 Preprocessor commands
6.1.1 Preprocessor macros
6.2 Conditional compilation
6.3 The pragma directive
6.4 Token concatenation
6.5 The \# operator
6.6 The include directive
6.7 Things to watch when using the preprocessor
7 More advanced stuff
7.1 Using function pointers
7.2 Using the "signal" function
7.2.1 Discussion
longjmp usage
Guard pages
8 Advanced C programming with lcc-win
8.1 Operator overloading
8.1.1 What is operator overloading?
8.1.2 Rules for the arguments
8.1.3 Name resolution
8.1.4 Differences to C++
8.2 Generic functions
8.2.1 Usage rules
8.3 Default arguments
8.4 References
9 Numerical programming
9.1 Floating point formats
9.1.1 Float (32 bit) format
9.1.2 Long double (80 bit) format
9.1.3 The qfloat format
9.1.4 Special numbers
9.2 Range
9.3 Precision
9.4 Understanding exactly the floating point format
9.5 Rounding modes
9.6 The machine epsilon
9.7 Rounding
9.8 Using the floating point environment
9.8.1 The status flags
9.8.2 Reinitializing the floating point environment
9.9 Numerical stability
9.9.1 Algebra doesn't work
9.9.2 Underflow
9.10 The math library
10 Memory management and memory layout
10.1 Functions for memory management
10.2 Memory management strategies
10.2.1 Static buffers
Advantages:
Drawbacks:
10.3 Stack based allocation
Advantages:
Drawbacks:
10.3.1 "Arena" based allocation
Advantages:
Drawbacks:
10.4 The malloc / free strategy
Advantages:
Drawbacks:
10.5 The malloc with no free strategy
Advantages:
Drawbacks:
10.6 Automatic freeing (garbage collection).
Advantages:
Drawbacks:
10.7 Mixed strategies
10.8 A debugging implementation of malloc
10.8.1 Improving allocate/release
11 The libraries of lcc-win
11.1 The regular expressions library.
11.2 Using qfloats: Some examples
11.3 Using bignums: some examples
12 Pitfalls of the C language
12.1 Defining a variable in a header file
12.2 Confusing = and ==
12.3 Forgetting to close a comment
12.4 Easily changed block scope.
12.5 Using increment or decrement more than once in an expression.
12.6 Unexpected Operator Precedence
12.7 Extra Semi-colon in Macros
12.8 Watch those semicolons!
12.9 Assuming pointer size is equal to integer size
12.10 Careful with unsigned numbers
12.11 Changing constant strings
12.12 Indefinite order of evaluation
12.13 A local variable shadows a global one
12.14 Careful with integer wraparound
12.15 Problems with integer casting
12.16 Octal numbers
12.17 Wrong assumptions with realloc
12.18 Be careful with integer overflow
12.18.1 Overflow in calloc
12.19 The abs macro can yield a negative number.
12.20 Adding two positive numbers might make the result smaller.
12.21 Assigning a value avoiding truncation
12.22 The C standard
12.22.1 Standard word salads
12.22.2 A buffer overflow in the C standard document
Getting rid of buffer overflows
Buffer overflows are not inevitable.
The attitude of the committee
12.22.3 A better implementation of asctime
13 Bibliography
Appendices
.1 Using the command line compiler