Contents

Table of Contents

List of Tables xv
Preface xvii

PART 1 The C Language 1

1 Introduction 3

1.1 The Evolution of C 3
1.2 Which Dialect of C Should You Use? 6
1.3 An Overview of C Programming 7
1.4 Conformance 8
1.5 Syntax Notation 9

2 Lexical Elements 11

2.1 Character Set 11
2.2 Comments 18
2.3 Tokens 20
2.4 Operators and Separators 20
2.5 Identifiers 21
2.6 Keywords 23
2.7 Constants 24
2.8 C++ Compatibility 38
2.9 On Character Sets, Repertoires, and Encodings 39
2.10 Exercises 41

3 The C Preprocessor 43

3.1 Preprocessor Commands 43
3.2 Preprocessor Lexical Conventions 44
3.3 Definition and Replacement 46
3.4 File Inclusion 59
3.5 Conditional Compilation 61
3.6 Explicit Line Numbering 66
3.7 Pragma Directive 67
3.8 Error Directive 69
3.9 C++ Compatibility 70
3.10 Exercises 71

4 Declarations 73

4.1 Organization of Declarations 74
4.2 Terminology 75
4.3 Storage Class and Function Specifiers 83
4.4 Type Specifiers and Qualifiers 86
4.5 Declarators 95
4.6 Initializers 103
4.7 Implicit Declarations 113
4.8 External Names 113
4.9 C++ Compatibility 116
4.10 Exercises 119

5 Types 123

5.1 Integer Types 124
5.2 Floating-Point Types 132
5.3 Pointer Types 136
5.4 Array Types 140
5.5 Enumerated Types 145
5.6 Structure Types 148
5.7 Union Types 160
5.8 Function Types 165
5.9 The Void Type 168
5.10 Typedef Names 168
5.11 Type Compatibility 172
5.12 Type Names and Abstract Declarators 176
5.13 C++ Compatibility 178
5.14 Exercises 179

6 Conversions and Representations 181

6.1 Representations 181
6.2 Conversions 188
6.3 The Usual Conversions 194
6.4 C++ Compatibility 200
6.5 Exercises 201

7 Expressions 203

7.1 Objects, Lvalues, and Designators 203
7.2 Expressions and Precedence 204
7.3 Primary Expressions 207
7.4 Postfix Expressions 210
7.5 Unary Expressions 219
7.6 Binary Operator Expressions 227
7.7 Logical Operator Expressions 242
7.8 Conditional Expressions 244
7.9 Assignment Expressions 246
7.10 Sequential Expressions 249
7.11 Constant Expressions 250
7.12 Order of Evaluation 253
7.13 Discarded Values 255
7.14 Optimization of Memory Accesses 256
7.15 C++ Compatibility 257
7.16 Exercises 258

8 Statements 259

8.1 General Syntactic Rules for Statements 260
8.2 Expression Statements 260
8.3 Labeled Statements 261
8.4 Compound Statements 262
8.5 Conditional Statements 264
8.6 Iterative Statements 266
8.7 Switch Statements 274
8.8 Break and Continue Statements 277
8.9 Return Statements 279
8.10 Goto Statements 280
8.11 Null Statements 281
8.12 C++ Compatibility 282
8.13 Exercises 282

9 Functions 285

9.1 Function Definitions 286
9.2 Function Prototypes 289
9.3 Formal Parameter Declarations 295
9.4 Adjustments to Parameter Types 298
9.5 Parameter-Passing Conventions 299
9.6 Agreement of Parameters 300
9.7 Function Return Types 301
9.8 Agreement of Return Types 302
9.9 The Main Program 303
9.10 Inline Functions 304
9.11 C++ Compatibility 306
9.12 Exercises 307

PART 2 The C Libraries 309

10 Introduction to the Libraries 311

10.1 Standard C Facilities 312
10.2 C++ Compatibility 313
10.3 Library Headers and Names 316

11 Standard Language Additions 325

11.1 NULL, ptrdiff_t, size_t, offsetof 325
11.2 EDOM, ERANGE, EILSEQ, errno, strerror, perror 327
11.3 bool, false, true 329
11.4 va_list, va_start, va_arg, va_end 329
11.5 Standard C Operator Macros 333

12 Character Processing 335

12.1 isalnum, isalpha, iscntrl, iswalnum, iswalpha, iswcntrl 336
12.2 iscsym, iscsymf 338
12.3 isdigit, isodigit, isxdigit, iswdigit, iswxdigit 338
12.4 isgraph, isprint, ispunct, iswgraph, iswprint, iswpunct 339
12.5 islower, isupper, iswlower, iswupper 340
12.6 isblank, isspace, iswhite, iswspace 341
12.7 toascii 341
12.8 toint 342
12.9 tolower, toupper, towlower, towupper 342
12.10 wctype_t, wctype, iswctype 343
12.11 wctrans_t, wctrans 344

13 String Processing 347

13.1 strcat, strncat, wcscat, wcsncat 348
13.2 strcmp, strncmp, wcscmp, wcsncmp 349
13.3 strcpy, strncpy, wcscpy, wcsncpy 350
13.4 strlen, wcslen 351
13.5 strchr, strrchr, wcschr, wcsrchr 351
13.6 strspn, strcspn, strpbrk, strrpbrk, wcsspn, wcscspn, wcspbrk 352
13.7 strstr, strtok, wcsstr, wcstok 354
13.8 strtod, strtof, strtold, strtol, strtoll, strtoul, strtoull 355
13.9 atof, atoi, atol, atoll 356
13.10 strcoll, strxfrm, wcscoll, wcsxfrm 356

14 Memory Functions 359

14.1 memchr, wmemchr 359
14.2 memcmp, wmemcmp 360
14.3 memcpy, memccpy, memmove, wmemcpy, wmemmove 361
14.4 memset, wmemset 362

15 Input/Output Facilities 363

15.1 FILE, EOF, wchar_t, wint_t, WEOF 365
15.2 fopen, fclose, fflush, freopen, fwide 366
15.3 setbuf, setvbuf 370
15.4 stdin, stdout, stderr 371
15.5 fseek, ftell, rewind, fgetpos, fsetpos 372
15.6 fgetc, fgetwc, getc, getwc, getchar, getwchar, ungetc, ungetwc 374
15.7 fgets, fgetws, gets 376
15.8 fscanf, fwscanf, scanf, wscanf, sscanf, swscanf 377
15.9 fputc, fputwc, putc, putwc, putchar, putwchar 385
15.10 fputs, fputws, puts 386
15.11 fprintf, printf, sprintf, snprintf, fwprintf, wprintf, swprintf 387
15.12 vfprintf, vfwprintf, vprintf, vwprintf, vsprintf, vswprintf, vfscanf, vfwscanf, vscanf, vwscanf, vsscanf, vswscanf 401
15.13 fread, fwrite 402
15.14 feof, ferror, clearerr 404
15.15 remove, rename 404
15.16 tmpfile, tmpnam, mktemp 405

16 General Utilities 407

16.1 malloc, calloc, mlalloc, clalloc, free, cfree 407
16.2 rand, srand, RAND_MAX 410
16.3 atof, atoi, atol, atoll l 411
16.4 strtod, strtof, strtold, strtol, strtoll, strtoul, strtoull 412
16.5 abort, atexit, exit, _Exit, EXIT_FAILURE, EXIT_SUCCESS 414
16.6 getenv 415
16.7 system 416
16.8 bsearch, qsort 417
16.9 abs, labs, llabs, div, ldiv, lldiv 419
16.10 mblen, mbtowc, wctomb 420
16.11 mbstowcs, wcstombs 422

17 Mathematical Functions 425

17.1 abs, labs, llabs, div, ldiv, lldiv 426
17.2 fabs 426
17.3 ceil, floor, lrint, llrint, lround, llround, nearbyint, round, rint, trunc 427
17.4 fmod, remainder, remquo 428
17.5 frexp, ldexp, modf, scalbn 429
17.6 exp, exp2, expm1, ilogb, log, log10, log1p, log2, logb 430
17.7 cbrt, fma, hypot, pow, sqrt 432
17.8 rand, srand, RAND_MAX 432
17.9 cos, sin, tan, cosh, sinh, tanh 433
17.10 acos, asin, atan, atan2, acosh, asinh, atanh 434
17.11 fdim, fmax, fmin 435
17.12 Type-Generic Macros 435
17.13 erf, erfc, lgamma, tgamma 439
17.14 fpclassify, isfinite, isinf, isnan, isnormal, signbit 440
17.15 copysign, nan, nextafter, nexttoward 441
17.16 isgreater, isgreaterequal, isless, islessequal, islessgreater, isunordered 442

18 Time and Date Functions 443

18.1 clock, clock_t, CLOCKS_PER_SEC, times 443
18.2 time, time_t 445
18.3 asctime, ctime 445
18.4 gmtime, localtime, mktime 446
18.5 difftime 447
18.6 strftime, wcsftime 448

19 Control Functions 453

19.1 assert, NDEBUG 453
19.2 system, exec 454
19.3 exit, abort 454
19.4 setjmp, longjmp, jmp_buf 454
19.5 atexit 456
19.6 signal, raise, gsignal, ssignal, psignal 456
19.7 sleep, alarm 458

20 Locale 461

20.1 setlocale 461
20.2 localeconv 463

21 Extended Integer Types 467

21.1 General Rules 467
21.2 Exact-Size Integer Types 470
21.3 Least-Size Types of a Minimum Width 471
21.4 Fast Types of a Minimum Width 472
21.5 Pointer-Size and Maximum-Size Integer Types 473
21.6 Ranges of ptrdiff_t, size_t, wchar_t, wint_t, and sig_atomic_t 474
21.7 imaxabs, imaxdiv, imaxdiv_t 474
21.8 strtoimax, strtouimax 475
21.9 wcstoimax, wcstoumax 475

22 Floating-Point Environment 477

22.1 Overview 477
22.2 Floating-Point Environment 478
22.3 Floating-Point Exceptions 479
22.4 Floating-Point Rounding Modes 481
23 Complex Arithmetic 483
23.1 Complex Library Conventions 483
23.2 complex, _Complex_I, imaginary, _Imaginary_I, I 484
23.3 CX_LIMITED_RANGE 484
23.4 cacos, casin, catan, ccos, csin, ctan 485
23.5 cacosh, casinh, catanh, ccosh, csinh, ctanh 486
23.6 cexp, clog, cabs, cpow, csqrt 487
23.7 carg, cimag, creal, conj, cproj 488

24 Wide and Multibyte Facilities 489

24.1 Basic Types and Macros 489
24.2 Conversions Between Wide and Multibyte Characters 490
24.3 Conversions Between Wide and Multibyte Strings 491
24.4 Conversions to Arithmetic Types 493
24.5 Input and Output Functions 493
24.6 String Functions 493
24.7 Date and Time Conversions 494
24.8 Wide-Character Classification and Mapping Functions 494

A The ASCII Character Set 497

B Syntax 499

C Answers to the Exercises 513

Index 521


This page was last updated 2002-02-16 14:05 -0500.