Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
C in a Nutshell
SPECIAL OFFER: Upgrade this ebook with O’Reilly
Preface
How This Book Is Organized
Part I
Part II
Part III
Further Reading
Conventions Used in This Book
Using Code Examples
Safari® Enabled
Your Questions and Comments
Acknowledgments
Peter
Tony
I. Language
1. Language Basics
1.1. Characteristics of C
1.2. The Structure of C Programs
1.3. Source Files
1.4. Comments
1.5. Character Sets
1.5.1. Wide Characters and Multibyte Characters
1.5.2. Universal Character Names
1.5.3. Digraphs and Trigraphs
1.6. Identifiers
1.6.1. Identifier Name Spaces
1.6.2. Identifier Scope
1.7. How the C Compiler Works
1.7.1. The C Compiler's Translation Phases
1.7.2. Tokens
2. Types
2.1. Typology
2.2. Integer Types
2.2.1. Integer Types with Exact Width (C99)
2.3. Floating-Point Types
2.4. Complex Floating-Point Types (C99)
2.5. Enumerated Types
2.6. The Type void
2.6.1. void in Function Declarations
2.6.2. Expressions of Type void
2.6.3. Pointers to void
3. Literals
3.1. Integer Constants
3.2. Floating-Point Constants
3.2.1. Decimal Floating-Point Constants
3.2.2. Hexadecimal Floating-Point Constants (C99)
3.3. Character Constants
3.3.1. The Type of Character Constants
3.3.2. Escape Sequences
3.4. String Literals
4. Type Conversions
4.1. Conversion of Arithmetic Types
4.1.1. Hierarchy of Types
4.1.2. Integer Promotion
4.1.3. Usual Arithmetic Conversions
4.1.4. Other Implicit Type Conversions
4.1.5. The Results of Arithmetic Type Conversions
4.1.5.1. Conversions to _Bool
4.1.5.2. Conversions to unsigned integer types other than _Bool
4.1.5.3. Conversions to signed integer types
4.1.5.4. Conversions to real floating-point types
4.1.5.5. Conversions to complex floating-point types
4.2. Conversion of Nonarithmetic Types
4.2.1. Array and Function Designators
4.2.2. Explicit Pointer Conversions
4.2.2.1. Object pointers
4.2.2.2. Function pointers
4.2.3. Implicit Pointer Conversions
4.2.3.1. Pointers to void
4.2.3.2. Pointers to qualified object types
4.2.3.3. Null pointer constants
4.2.4. Conversions Between Pointer and Integer Types
5. Expressions and Operators
5.1. How Expressions Are Evaluated
5.1.1. Lvalues
5.1.2. Side Effects and Sequence Points
5.1.3. Operator Precedence and Associativity
5.2. Operators in Detail
5.2.1. Arithmetic Operators
5.2.1.1. Standard arithmetic
5.2.1.2. Pointer arithmetic
5.2.2. Assignment Operators
5.2.2.1. Simple assignment
5.2.2.2. Compound assignments
5.2.3. Increment and Decrement Operators
5.2.4. Comparative Operators
5.2.5. Logical Operators
5.2.6. Bitwise Operators
5.2.6.1. Boolean bitwise operators
5.2.6.2. Shift operators
5.2.7. Memory Addressing Operators
5.2.7.1. The & and * operators
5.2.7.2. Elements of arrays
5.2.7.3. Members of structures and unions
5.2.8. Other Operators
5.2.8.1. Function calls
5.2.8.2. Compound literals
5.2.8.3. The sizeof operator
5.2.8.4. The conditional operator
5.2.8.5. The comma operator
5.3. Constant Expressions
5.3.1. Integer Constant Expressions
5.3.2. Other Constant Expressions
6. Statements
6.1. Expression Statements
6.2. Block Statements
6.3. Loops
6.3.1. while Statements
6.3.2. for Statements
6.3.3. do...while Statements
6.3.4. Nested Loops
6.4. Selection Statements
6.4.1. if Statements
6.4.2. switch Statements
6.5. Unconditional Jumps
6.5.1. The break Statement
6.5.2. The continue Statement
6.5.3. The goto Statement
6.5.4. The return Statement
7. Functions
7.1. Function Definitions
7.1.1. Functions and Storage Class Specifiers
7.1.2. K&R-Style Function Definitions
7.1.3. Function Parameters
7.1.4. Arrays as Function Parameters
7.1.5. The main() Function
7.2. Function Declarations
7.2.1. Declaring Optional Parameters
7.2.2. Declaring Variable-Length Array Parameters
7.3. How Functions Are Executed
7.4. Pointers as Arguments and Return Values
7.5. Inline Functions
7.6. Recursive Functions
7.7. Variable Numbers of Arguments
8. Arrays
8.1. Defining Arrays
8.1.1. Fixed-Length Arrays
8.1.2. Variable-Length Arrays
8.2. Accessing Array Elements
8.3. Initializing Arrays
8.3.1. Writing Initialization Lists
8.3.2. Initializing Specific Elements
8.4. Strings
8.5. Multidimensional Arrays
8.5.1. Matrices
8.5.2. Declaring Multidimensional Arrays
8.5.3. Initializing Multidimensional Arrays
8.6. Arrays as Arguments of Functions
9. Pointers
9.1. Declaring Pointers
9.1.1. Null Pointers
9.1.2. void Pointers
9.1.3. Initializing Pointers
9.2. Operations with Pointers
9.2.1. Using Pointers to Read and Modify Objects
9.2.2. Modifying and Comparing Pointers
9.3. Pointers and Type Qualifiers
9.3.1. Constant Pointers and Pointers to Constant Objects
9.3.2. Restricted Pointers
9.4. Pointers to Arrays and Arrays of Pointers
9.4.1. Array Pointers
9.4.2. Pointer Arrays
9.5. Pointers to Functions
10. Structures and Unions and Bit-Fields
10.1. Structures
10.1.1. Defining Structure Types
10.1.2. Structure Objects and typedef Names
10.1.3. Incomplete Structure Types
10.1.4. Accessing Structure Members
10.1.5. Initializing Structures
10.1.6. Initializing Specific Members
10.1.7. Structure Members in Memory
10.1.8. Flexible Structure Members
10.1.9. Pointers as Structure Members
10.2. Unions
10.2.1. Defining Union Types
10.2.2. Initializing Unions
10.3. Bit-Fields
11. Declarations
11.1. General Syntax
11.1.1. Examples
11.1.2. Storage Class Specifiers
11.1.3. Type Qualifiers
11.1.4. Declarations and Definitions
11.1.5. Complex Declarators
11.2. Type Names
11.3. typedef Declarations
11.4. Linkage of Identifiers
11.4.1. External Linkage
11.4.2. Internal Linkage
11.4.3. No Linkage
11.5. Storage Duration of Objects
11.5.1. Static Storage Duration
11.5.2. Automatic Storage Duration
11.6. Initialization
11.6.1. Implicit Initialization
11.6.2. Explicit Initialization
12. Dynamic Memory Management
12.1. Allocating Memory Dynamically
12.2. Characteristics of Allocated Memory
12.3. Resizing and Releasing Memory
12.4. An All-Purpose Binary Tree
12.5. Characteristics
12.6. Implementation
12.6.1. Generating an Empty Tree
12.6.2. Inserting New Data
12.6.3. Finding Data in the Tree
12.6.4. Removing Data from the Tree
12.6.5. Traversing a Tree
12.6.6. A Sample Application
13. Input and Output
13.1. Streams
13.1.1. Text Streams
13.1.2. Binary Streams
13.2. Files
13.2.1. File Position
13.2.2. Buffers
13.2.3. The Standard Streams
13.3. Opening and Closing Files
13.3.1. Opening a File
13.3.2. Access Modes
13.3.3. Closing a File
13.4. Reading and Writing
13.4.1. Byte-Oriented and Wide-Oriented Streams
13.4.2. Error Handling
13.4.2.1. Return values and status flags
13.4.2.2. The error variable errno
13.4.3. Unformatted I/O
13.4.3.1. Reading characters
13.4.3.2. Putting a character back
13.4.3.3. Writing characters
13.4.3.4. Reading strings
13.4.3.5. Writing strings
13.4.3.6. Reading and writing blocks
13.4.4. Formatted Output
13.4.4.1. The printf() function family
13.4.4.2. The format string
13.4.4.3. Field widths
13.4.4.4. Printing characters and strings
13.4.4.5. Printing integers
13.4.4.6. Printing floating-point numbers
13.4.5. Formatted Input
13.4.5.1. The scanf() function family
13.4.5.2. The format string
13.4.5.3. Field widths
13.4.5.4. Reading characters and strings
13.4.5.5. Reading integers
13.4.5.6. Reading floating-point numbers
13.5. Random File Access
13.5.1. Obtaining the Current File Position
13.5.2. Setting the File Access Position
14. Preprocessing Directives
14.1. Inserting the Contents of Header Files
14.1.1. How the Preprocessor Finds Header Files
14.1.2. Nested #include Directives
14.2. Defining and Using Macros
14.2.1. Macros Without Parameters
14.2.2. Macros with Parameters
14.2.2.1. Variable numbers of arguments
14.2.2.2. The stringify operator
14.2.2.3. The token-pasting operator
14.2.3. Using Macros Within Macros
14.2.4. Macro Scope and Redefinition
14.3. Conditional Compiling
14.3.1. The #if and #elif Directives
14.3.2. The defined Operator
14.3.3. The #ifdef and #ifndef Directives
14.4. Defining Line Numbers
14.5. Generating Error Messages
14.6. The #pragma Directive
14.7. The _Pragma Operator
14.8. Predefined Macros
II. Standard Library
15. The Standard Headers
15.1. Using the Standard Headers
15.1.1. Execution Environments
15.1.2. Function and Macro Calls
15.1.3. Reserved Identifiers
15.2. Contents of the Standard Headers
15.2.1. assert.h
15.2.2. complex.h
15.2.3. ctype.h
15.2.4. errno.h
15.2.5. fenv.h
15.2.5.1. Macro and type definitions for the floating-point environment
15.2.5.2. Macro and type definitions for floating-point exceptions
15.2.5.3. Macro definitions for rounding modes
15.2.6. float.h
15.2.6.1. Normalized representation of floating-point numbers
15.2.6.2. Rounding mode and evaluation method
15.2.6.3. Precision and value range
15.2.7. inttypes.h
15.2.7.1. Types
15.2.7.2. Functions
15.2.7.3. Macros
15.2.8. iso646.h
15.2.9. limits.h
15.2.10. locale.h
15.2.11. math.h
15.2.11.1. The types float_t and double_t
15.2.11.2. Classification macros
15.2.11.3. Other macros in math.h
15.2.12. setjmp.h
15.2.13. signal.h
15.2.14. stdarg.h
15.2.15. stdbool.h
15.2.16. stddef.h
15.2.17. stdint.h
15.2.17.1. Value ranges of the integer types with specific widths
15.2.17.2. Value ranges of other integer types
15.2.17.3. Macros for integer constants
15.2.18. stdio.h
15.2.19. stdlib.h
15.2.20. string.h
15.2.21. tgmath.h
15.2.22. time.h
15.2.23. wchar.h
15.2.24. wctype.h
16. Functions at a Glance
16.1. Input and Output
16.2. Mathematical Functions
16.2.1. Mathematical Functions for Integer Types
16.2.2. Floating-Point Functions
16.2.3. Function-like Macros
16.2.3.1. Type-generic macros
16.2.3.2. Categories of floating-point values
16.2.3.3. Comparison macros
16.2.4. Pragmas for Arithmetic Operations
16.2.5. The Floating-Point Environment
16.2.5.1. Accessing status flags
16.2.5.2. Rounding modes
16.2.5.3. Saving the whole floating-point environment
16.2.6. Error Handling
16.2.6.1. Domain errors
16.2.6.2. Range errors
16.3. Character Classification and Conversion
16.3.1. Character Classification
16.3.2. Case Mapping
16.4. String Processing
16.5. Multibyte Characters
16.6. Converting Between Numbers and Strings
16.7. Searching and Sorting
16.8. Memory Block Handling
16.9. Dynamic Memory Management
16.10. Date and Time
16.11. Process Control
16.11.1. Communication with the Operating System
16.11.2. Signals
16.12. Internationalization
16.13. Nonlocal Jumps
16.14. Debugging
16.15. Error Messages
17. Standard Library Functions
_Exit C99
abort
abs
acos
acosh C99
asctime
asin
asinh C99
assert
atan
atan2
atanh C99
atexit
atof
atoi
atol, atoll
bsearch
btowc
cabs C99
cacos C99
cacosh C99
calloc
carg C99
casin C99
casinh C99
catan C99
catanh C99
cbrt C99
ccos C99
ccosh C99
ceil
cexp C99
cimag C99
clearerr
clock
conj C99
copysign C99
cos
cosh
cpow C99
cproj C99
creal C99
csin C99
csinh C99
csqrt C99
ctan C99
ctanh C99
ctime
difftime
div
erf C99
erfc C99
exit
exp
exp2 C99
expm1 C99
fabs
fclose
fdim C99
feclearexcept C99
fegetenv C99
fegetexceptflag C99
fegetround C99
feholdexcept C99
feof
feraiseexcept C99
ferror
fesetenv C99
fesetexceptflag C99
fesetround C99
fetestexcept C99
feupdateenv C99
fflush
fgetc
fgetpos
fgets
fgetwc
fgetws
floor
fma C99
fmax C99
fmin C99
fmod
fopen
fpclassify C99
fprintf
fputc
fputs
fputwc
fputws
fread
free
freopen
frexp
fscanf
fseek
fsetpos
ftell
fwide
fwprintf
fwscanf
fwrite
getc
getchar
getenv
gets
getwc
getwchar
gmtime
hypot C99
ilogb C99
imaxabs C99
imaxdiv C99
isalnum
isalpha
isblank C99
iscntrl
isdigit
isfinite C99
isgraph
isgreater, isgreaterequal C99
isinf C99
isless, islessequal, islessgreater C99
islower
isnan C99
isnormal C99
isprint
ispunct
isspace
isunordered C99
isupper
iswalnum
iswalpha
iswblank C99
iswcntrl
iswctype
iswdigit
iswgraph
iswlower
iswprint
iswpunct
iswspace
iswupper
iswxdigit
isxdigit
labs
ldexp
ldiv
llabs C99
lldiv C99
llrint
llround
localeconv
localtime
log
log10
log1p C99
log2 C99
logb C99
longjmp
lrint C99
lround C99
malloc
mblen
mbrlen
mbrtowc C99
mbsinit
mbsrtowcs
mbstowcs
mbtowc
memchr
memcmp
memcpy
memmove
memset
mktime
modf
nearbyint C99
nextafter C99
nexttoward C99
perror
pow
printf
putc
putchar
puts
putwc
putwchar
qsort
raise
rand
realloc
remainder C99
remove
remquo C99
rename
rewind
rint C99
round C99
scalbln, scalbn C99
scanf
setbuf
setjmp
setlocale
setvbuf
signal
signbit C99
sin
sinh
snprintf
sprintf
sqrt
srand
sscanf
strcat
strchr
strcmp
strcoll
strcpy
strcspn
strerror
strftime
strlen
strncat
strncmp
strncpy
strpbrk
strrchr
strspn
strstr
strtod, strtof, strtold
strtoimax C99
strtok
strtol, strtoll
strtoul, strtoull
strtoumax C99
strxfrm
swprintf
swscanf
system
tan
tanh
time
tmpfile
tmpnam
tolower
toupper
towctrans
towlower
towupper
trunc C99
ungetc
ungetwc
va_arg, va_copy, va_end, va_start
vfprintf, vprintf, vsnprintf, vsprintf
vfscanf, vscanf, vsscanf
vfwprintf, vswprintf, vwprintf
vfwscanf, vswscanf, vwscanf
wcrtomb
wcscat
wcschr
wcscmp
wcscoll
wcscpy
wcscspn
wcsftime
wcslen
wcsncat
wcsncmp
wcsncpy
wcspbrk
wcsrchr
wcsrtombs
wcsspn
wcsstr
wcstod, wcstof, wcstold
wcstoimax C99
wcstok
wcstol, wcstoll
wcstold
wcstoll
wcstombs
wcstoul, wcstoull
wcstoumax C99
wcsxfrm
wctob
wctomb
wctrans
wctype
wmemchr
wmemcmp
wmemcpy
wmemmove
wmemset
wprintf
wscanf
III. Basic Tools
18. Compiling with GCC
18.1. The GNU Compiler Collection
18.2. Obtaining and Installing GCC
18.3. Compiling C Programs with GCC
18.3.1. Step by Step
18.3.1.1. Preprocessing
18.3.1.2. Compiling
18.3.1.3. Assembling
18.3.1.4. Linking
18.3.1.5. All of the above
18.3.1.6. None of the above
18.3.2. Multiple Input Files
18.3.2.1. File types
18.3.2.2. Mixed input types
18.3.3. Dynamic Linking and Shared Object Files
18.3.4. Freestanding Programs
18.4. C Dialects
18.5. Compiler Warnings
18.6. Optimization
18.6.1. The -O Levels
18.6.2. The -f Flags
18.6.3. Floating-Point Optimization
18.6.4. Architecture-Specific Optimization
18.6.5. Why Not Optimize?
18.7. Debugging
18.8. Profiling
18.9. Option and Environment Variable Summary
18.9.1. Command-Line Options
18.9.2. Environment Variables
19. Using make to Build C Programs
19.1. Targets, Prerequisites, and Commands
19.2. The Makefile
19.3. Rules
19.3.1. The Command Script
19.3.2. Pattern Rules
19.3.3. Suffix Rules
19.3.4. Built-in Rules
19.3.5. Implicit Rule Chains
19.3.6. Double-Colon Rules
19.4. Comments
19.5. Variables
19.5.1. Assignment Operators
19.5.2. Variables and Whitespace
19.5.3. Target-Specific Variable Assignments
19.5.4. The Automatic Variables
19.5.5. Other Built-in Variables
19.5.6. Environment Variables
19.6. Phony Targets
19.7. Other Target Attributes
19.8. Macros
19.9. Functions
19.9.1. Built-in Functions
19.9.1.1. Text-processing functions
19.9.1.2. Filename-manipulation functions
19.9.1.3. Conditions and flow control functions
19.9.1.4. Operations on variables
19.9.1.5. System functions
19.9.2. User-Defined Functions
19.10. Directives
19.10.1. Conditionals
19.10.2. Includes
19.10.3. Other Directives
19.11. Running make
19.11.1. Generating Header Dependencies
19.11.2. Recursive make Commands
19.11.3. Command-Line Options
19.11.4. Special Targets Used as Runtime Options
19.11.5. GCC Options for Generating Makefile Rules
20. Debugging C Programs with GDB
20.1. Installing GDB
20.2. A Sample Debugging Session
20.2.1. Symbol Information
20.2.2. Finding a Bug
20.3. Starting GDB
20.3.1. Command-Line Arguments
20.3.2. Command-Line Options
20.3.2.1. Passing arguments to the program being debugged
20.3.2.2. Selecting files
20.3.2.3. Selecting the user interface
20.3.2.4. Executing command scripts
20.3.3. Initialization Files
20.4. Using GDB Commands
20.4.1. Command Completion
20.4.2. Displaying Help for Commands
20.4.3. Status Information
20.4.3.1. Status information on the program being debugged
20.4.3.2. Status information on the debugger
20.4.4. Running a Program in the Debugger
20.4.5. Displaying Source Code
20.4.6. Working with Breakpoints
20.4.6.1. Setting and displaying breakpoints
20.4.6.2. Deleting, disabling, and ignoring breakpoints
20.4.6.3. Conditional breakpoints
20.4.7. Resuming Execution After a Break
20.4.8. Analyzing the Stack
20.4.8.1. Displaying a call trace
20.4.8.2. Displaying and changing the current stack frame
20.4.8.3. Displaying arguments and local variables
20.4.9. Displaying Data
20.4.9.1. Displaying values of expressions
20.4.9.2. Output formats
20.4.9.3. Displaying memory blocks
20.4.10. Watchpoints: Observing Operations on Variables
20.4.11. Analyzing Core Files in GDB
Index
About the Authors
Colophon
SPECIAL OFFER: Upgrade this ebook with O’Reilly
← Prev
Back
Next →
← Prev
Back
Next →