Você está na página 1de 16

415

I
Index

SYMBOLS addresses
array tags, 183-184
# (stringizing operator) and macros, 89 base, 178
## (concatenation operator), 101-102 beyond array endpoints, 177-179
macros, 89 offset, 178
% (modulus operator), 14 printing, 157-158
&array_name compared to array_name, algorithms
184 searching, 32-33
*/ symbol (comments), 98 bsearch( ) function, 48-50
++ operator (increment operator), 13 complexity, 33-34
++var compared to var++, 13-14 sorting, 31-34
/* symbol (comments), 98 Allman brace style, 338
// symbol (comments), 98, 279 allocating
32-bit compilers, 356-357 file handles, 81
64KB limit for arrays, 150 memory, 132-158
heaps, 152-153
A malloc( ) and calloc( ), 149
sizing, 156
Abort message, 81-83 stacks, 151-152
access Windows, 413
denying file access, 79 alphabetical characters, 374-375
DOS (Disk Operating System) memory animated bitmaps, Windows, 403
locations, 260-262 animated text, writing text to screen, 296
acos( ) function, 239 ANSI (American National Standards
adding Institute), 283-291
pointers, 143-144 C++ (Windows compiler compatibility),
values to pointers, 141-142 395
416 ANSI

compared to BIOS functions, lvalues, 11-12 compared to text mode, 67


264-265 navigating with pointers or searches, 49
ANSI driver, 310-314 subscripts, 181-183 pointers, 139
ANSI.SYS device driver (escape passing to functions, 167-169 streams, 67
characters), 382 pointers, 180 see also comparison searching
ANSI/ISO C standard, 110-111 sizeof operator, 179-180 BIOS (Basic Input Output
cursor positioning, 295 sizing at runtime, 147-148 System), 255, 262
variables subscripts, 176-177 ANSI functions, 264-265
declaring, 271 arrow keys, 304-305 calling functions, 258-260
environment variables, 256 ASCII (American Standard controlling a mouse, 272-273
significance for names, 340 Code for Information DOS, 262
applicability of command-line Interchange) character set, graphics mode, changing,
parameters, 351-352 189-190 265-269
applications alphabetical characters, BIT_POS( ) macro, 192
compiling, 315-329 374-375 BIT_RANGE( ) macro, 193
Ctrl-Break (stopping NUL, 155 BIT_SHIFT( ) macro, 193
execution), 300-301 asin( ) function, 239 bitmaps, animated (Windows),
data transfer, 363-368 assert( ) function, 212-213 403
directories of executing assigning bits, 189-196
applications, 368-369 hexadecimal values to binary numbering, 378
fitting to DOS, 324-325 variables, 376 masking, 191-194
interrupting (Windows), octal values to numbers, 377 portability of bit fields, 194
357-360 assignment operators, operator bitshifting
preprocessor, 90-92 precedence, 287 and multiplication by 2,
running, 361-363 assignment statements, 10-12 194-195
writing, 315-329 associativity, operator operator precedence, 286
argc argument parameter precedence, 270-271 braces, styles of usage, 338-339
(command-line parameters), atan( ) function, 239 Break key, disabling, 301
350 atan2( ) function, 239 break statements
arguments, declaring in atexit( ) function and cleanup continue statements, 346
argument lists, 288-289 operations, 169-170 switch statements, 5
argv argument parameter atoi( ) function, 126-128 breakpoints, setting, 205
(command-line parameters), attributes of files, 75-76 bsearch( ) function, 48-50
350 AUTOEXEC.BAT file buffering output, 293-294
arithmetic operations environment variables, 256 bus errors, 155-156
listing VII.7, 140-141 printing, 341 buttons, 407-408
type casts, 26 bytes, 189-196
void pointers, 157 B binary numbering, 378
array_name, compared to bank switching, memory bit masking, 191-194
&array_name, 184 management, 326 color bytes (writing data to the
arrays, 176-187 base (addresses), 178 screen), 298-300
64KB limit, 150 base 2 (binary numbering), high-order bytes, 195
addressing 377-379 low-order bytes, 195
array tags, 183-184 base 8 (octal numbering), 379 byval_func( ) function, 167
beyond array endpoints, base 16 (hexadecimal
177-179 numbering), 380-381 C
calloc( ) function, 149 BeginPaint( ) function, 390 C, 1-14
char, 226 big-endian, compared to // for comments, 279
compared to strings, 186-187 little-endian, 280-281 ANSI, 110-111, 283-291
constant values, 185 binary numbering system, C++ compiler additions, 277
377-379
constants 417

comma operator, 6-7 camel notation (naming .COM files, 319


compared to C++, 277-279 conventions), 336 comma operator, 6-7
compiling (_ _cplusplus caption bars, see title bars operator precedence, 287
symbol), 106 capturing mouse clicks comma-delimited text, 83-85
data files, 63-85 (Windows), 402-403 command-line parameters,
functions, 159-173 carets compared to cursors 349-352
goto statements, 8-10 (Windows), 401-402 commands, File menu,
ISO, 283-291 ceil( ) function, 240 Exit, 388
local blocks, 1-3 Central Processing Unit (CPU), commenting out code
longjmp( ) function, 8-10 263 (preprocessor), 98-99
loops, 7-8 chaining collisions, 55 comments, 208
lvalues, 10-11 char arrays, 226 */ symbol, 98
memory allocation, 132-158 character sets (OEM key codes), /* symbol, 98
modulus operator (%), 14 397-398 // symbol, 98, 279
object-oriented design, 278 characters program efficiency, 333-334
operator precedence, 12-13 alphabetical characters, comp( ) function, 37, 49
pointers, 132-158 374-375 Compact memory model,
preprocessor, 87-113 color, printing to screen, 260 317-319
rvalues, 12 determining classes of, comparing strings, 129-130,
setjmp( ) function, 8-10 232-233 228
strings, 116-130 field restrictions, 305-307 comparison searching, 33
switch statements, 3-5 multibyte characters, 240-241 compile date and time, printing
var++ compared to ++var, numerical characters, 375-376 (preprocessor), 110
13-14 chars, 280 compile-time checking,
Windows, 385-414 child windows, 407-408 205-207
C Programming Language, The, cleanup operations and compilers
338, 353 atexit( ), 169-170 32-bit compilers, 356-357
C++ clearing screens with the ANSI warnings, 207
ANSI (Windows compiler driver, 311 Windows compatibility,
compatibility), 395 clicks, capturing (Windows), 394-395
compared to C, 277-279 402-403 compiling
compiler additions in C client areas (Windows) C++ (_ _cplusplus symbol),
programs, 277 mouse clicks, capturing, 106
compiling (_ _cplusplus 402-403 programs, 315-329
symbol), 106 repainting, 395-396 complexity, 33-34
main( ) function, 290 sizing, 396-397 concatenating strings, 228
object-oriented design, 278 code concatenation operator (##),
Windows SDK, 392 commenting out code 101-102
callback (function pointers), (preprocessor), 98-99 macros, 89
145 portability, 275-281 conditional expressions
calling sort/search examples, 57-62 compilation (preprocessor), 91
BIOS functions, 258-260 collisions, hashing, 55 operator precedence, 287
DOS functions, 257-258 color const modifier, 21-22, 29
calloc( ) function, 324 screen color (ANSI driver), const pointers, 18-19
arrays, 149 312 const_func( ) function, 169
compared to malloc( ) system colors (Windows), constants
function, 149 405-406 arrays, 185
memory leaks, 203 text color (ANSI driver), declaring with
zero bits, 149 312-313 const, 29
CallWindowProc( ) function, color bytes, writing data to the #define, 93-94
409 screen, 298-300 enum, 94
418 constants

enum compared to #define, ctype.h header file, 232 converting to single numbers,
95-96 curses package (cursor 243-247
system colors (Windows), positioning), 295 sorting, 245
406-407 cursors storing, 243-247, 252
type casts, 27 compared to carets dead keys (Windows), 400-401
volatile variables, 21 (Windows), 401-402 debugging, 197-213
continue vs. break statements, moving (ANSI driver), equality operators, 206
346 313-314 excessive execution time,
controls, 407-408 positioning, 294-295 200-202
conventions restoring cursor positions failed conditions, 212-213
naming (variables), 332 (ANSI driver), 312 hanging programs, 197-203
programs, 233 saving cursor positions (ANSI implicitly cast variables,
converting driver), 311-312 206-207
date variables to single infinite loops, 199-200
numbers, 243-247 D input problems, 202-203
numbers to strings, 124-126 data files, 63-85 memory leaks, 203-204
strings to numbers, 126-128 Abort, Fail, Retry messages, methods, 204-211
time variables to single 81-83 nested for loops, 202
numbers, 248-251 attributes, 75-76 symbolic debuggers
cooperative multitasking, 357 binary mode, 67 (enumerated constants), 96
copying comma-delimited text, 83-85 tools, 205-207
string sections, 123-124 date and time lists, 70-72 TSR (terminate and stay
strings, 228 denying access, 79 resident) programs, 211-212
core dumps, 155-156 errno variable and nonzero uninitialized variables, 206
cos( ) function, 239 numbers, 63-64 declaring
cosh( ) function, 239 file handle allocation, 81 arguments in argument lists,
_ _cplusplus symbol and file lists in directories, 68-69 288-289
compiling C++, 106 filename sorting in directories, array sizes at runtime, 147-148
CPU (Central Processing Unit), 73-74 constants with
263 locking files, 79-80 const, 29
CreateDialog( ) function, 414 opening in shared mode, #decline, 93-94
CreatePen( ) function, 390 77-79 enum, 94
CreateWindow( ) function, 388, passing data, 363-368 functions, 159-162
407-408 PATH environment variable, static variables in headers, 28
edit class, 410-411 76-77 variables, 28, 271
listbox class, 411-412 sharing files, 79-80 in headers, 27
creating storing data, 16-29 local blocks, 2
buttons (Windows), 407-408 streams, 64 default cases, 4-5
.COM files, 319 text mode, 67 #define directive (preprocessor),
controls (Windows), 407-408 writing to the screen, 295-296 92
delay timers for DOS, 353 data segments (variable constant declarations, 93-94
libraries, 321-322 storage), 16 compared to enumerated
random numbers, 354-356 data types and scanf( ), 303 constants, 95-96
critical error handler (interrupt _ _DATE_ _ preprocessor macros, 88-89
24), 81 command, 109-110 undefining (preprocessor),
Ctrl-Alt-Delete (disabling warm date and time, 70-72 111-112
boots), 372-374 compile date and time true/false, 344
Ctrl-Break (stopping program (preprocessor), 110 defining
execution), 300-301 Windows, 404 headers at compile time
disabling, 370-372 date variables, 243-253 (preprocessor), 100
Windows program interrupts, NULL as 0, 142
388
factorials,calculating 419

standard library functions, DOS (Disk Operating System) errno variable (nonzero
216-223 BIOS, 262 numbers), 63-64
true/false, 344-345 command-line parameters, error handling
variables, 27-28 351-352 bus errors, 155-156
DefWindowProc( ) function, delay timers, 353 core dumps, 155-156
402 fitting applications, 324-325 debugging, 197-213
delay timers functions DGROUP: group exceeds
creating for DOS, 353 calling, 257-258 64K message, 323-324
Windows, 387 compared to Windows, excessive program execution
demo programs, disabling 392-393 time, 200-202
(preprocessor), 97 interrupts 62, command-line hardware, 81-83
denying file access, 79 parameters, 352 infinite loops, 199-200
detecting memory leaks, memory locations, accessing, input problems, 202-203
203-204 260-262 memory faults, 155-156
device contexts, 386 undocumented functions, 258 null pointers, 137
GDI (Graphic Device DOS Busy Flag, 258 assignment errors, 155-156
Interface), 389 DOS extenders (memory preventing, 208-211
HDC (handle), 394 management), 325 printing error locations
DGROUP: group exceeds 64K double-precision floating point, (preprocessor), 104
message, 323-324 239 source file errors, printing
dialog boxes (modal and doubles (numbers), 308 (preprocessor), 105
modeless), 414 dup( ) function, 65-66 escape characters, 382-383
DialogBox( ) function, 414 dynamic linking (Windows), events, see interrupts
digital trie searching algorithm, 393 exception handling, 352
50-55 dynamic memory exchange sorts, 32
directories allocating, 324 .EXE files, 319-321
filenames, sorting, 73-74 calloc( ), 149 printf( ) function, 296
listing files, 68-69 malloc( ), 149 exec( ) function, 361-362
searching for executing memory leaks, 203 execution
programs, 368-369 loops, 7-8
disabling E sequential program execution,
Break key, 301 edit class (Windows), 410-411 361-362
Ctrl-Break, 370-372 editing in Windows, 401-402 simultaneous program
demo programs (preprocessor), efficiency of programs execution, 362-363
97 comments, 333-334 stopping with Ctrl-Break,
warm boots (Ctrl-Alt-Delete), naming variables, 336-337 300-301
372-374 recursion, 343 Exit command (File menu), 388
disk swapping (memory white space, 334-336 exit( ) function and return
management), 325 EMS (expanded memory), 326 statements, 171-173
display modes, 265-269 enumerated constants exiting Windows programs,
screen output, 293-294 compared to #define 388-389
distribution sorts, 32 (symbolic) constants, 95-96 exp( ) function, 239
DLLs (dynamic link libraries) declaring constants, 94 expanded memory (EMS), 326
and Windows, 393 symbolic debuggers, 96 extended display modes, 268
dollars-and-cents values, use with true/false, 344 extended memory (XMS), 326
printing, 307-309 environment variables, 256-257 external scope, 165
_dos_findfirst( ) function, environments, free-standing external sorts, 32, 44-48
68-69, 369 and hosted, 225
_dos_findnext( ) function, equality operators F
68-69, 369 compile-time checking, 206 fabs( ) function, 240
_dos_getvect( ) function, 374 precedence, 286 factorials, calculating, 342-344
420 Fail message

Fail message, 81-83 formatted text, 295 257-258


false/true, defining, 344-345 fprintf( ) function, 83-85 _dos_findfirst( ), 68-69, 369
far compared to near, 327-329 free( ) function, 152-154, 156, _dos_findnext( ), 68-69, 369
FAR PASCAL declarations 324 _dos_getvect( ), 374
(Windows functions), 392 alternative versions, 236-239 dup( ), 65-66
far pointers, 151 memory management, error prevention, 208-209
compared to near pointers, 156-157 exec( ), 361-362
150-151 free-standing vs. hosted exit( ), 171-173
writing data to the screen, 298 environments, 225 exp( ), 239
fcvt( ) function, 125-126 freeing pointers twice, 153-154 fabs( ), 240
fdopen( ) function, 65-66 freopen( ) function, 65 fcvt( ), 125-126
fflush( ) function, 294 frexp( ) function, 240 fdopen( ), 65-66
Fibonacci numbers, 201 fscanf( ) function, 83-85 fflush( ), 294
fields, character restrictions of, functions, 159-173 filter functions, interrupting
305-307 acos( ), 239 programs, 357-360
_ _FILE_ _ preprocessor ANSI vs. BIOS, 264-265 floor( ), 240
command, 108 arguments, declaring in lists, fmod( ), 240
File menu, Exit command, 388 288-289 fprintf( ), 83-85
filenames, sorting in directories, array passing, 167-169 free( ), 152-154, 156-157, 324
73-74 asin( ), 239 alternative versions,
files assert( ), 212-213 236-239
Abort, Fail, Retry messages, atan( ), 239 freopen( ), 65
81-83 atan2( ), 239 frexp( ), 240
attributes, 75-76 atexit( ) and cleanup fscanf( ), 83-85
comma-delimited text, 83-85 operations, 169-170 getch( ), 257
denying access, 79-85 atoi( ), 126-128 getche( ), 258
finding, 369-370 BeginPaint( ), 390 getenv( ), 76-77, 256
handles BIOS functions, calling, GetKeyState( ), 400
allocating, 81 258-260 GetSysColor( ), 405-406
Windows, 387-388 bsearch( ), 48-50 GetWindowLong( ), 409
listing in directories, 68-69 byval_func( ), 167 glob_func( ), 160-161
locking, 79-80 callback (pointers), 145 GlobalAlloc( ), 413-414
opening in shared mode, calloc( ), 149, 324 GlobalFree( ), 414
77-79 memory leaks, 203 GlobalLock( ), 414
sharing, 79-80 CallWindowProc( ), 409 GlobalUnlock( ), 414
filter functions, interrupting ceil( ), 240 harderr( ), 81-83
programs, 357-360 comp( ), 37, 49 hardresume( ), 81
fitting applications to DOS, compared to macros hardretn( ), 81
324-325 (preprocessor), 98 header files, declaring
fixed segments (Windows), const_func( ), 169 variables, 271
412-413 cos( ), 239 int86( ), 257, 263
flags, 190-193 cosh( ), 239 int86x( ), 257, 263
Flash EPROM chip, 262 CreateDialog( ), 414 InvalidateRect( ), 395
floating-point comparisons, CreatePen( ), 390 isalnum( ), 232
22-24, 239-240 CreateWindow( ), 388, isalpha( ), 232
floats (numbers), 308 407-408, 410-412 iscntrl( ), 232
floor( ) function, 240 debugging, 198-199 isdigit( ), 232
flushing output buffers, 294 declaring, 159-162 isgraph( ), 232
fmod( ) function, 240 DefWindowProc( ), 402 islower( ), 232
for loops, nested, 202 DialogBox( ), 414 isprint( ), 232
for statements (comma DOS functions, calling, ispunct( ), 232
operators), 6-7
global heap 421

isspace( ), 232 165-166 static functions, 165-166


isupper( ), 232 open_customer_table( ), strcat( ), 228
isxdigit( ), 232 165-166 strchr( ), 228
itoa( ), 124-126 parameters, 163-165 strcmp( ), 37, 129-130,
jumping out, 233-235 PASCAL-declared functions, 146-147, 228
KbIntProc( ), 374 170-171 strcoll( ), 233
KeyBoardProc( ), 360 PeekMessage( ), 357 strcpy( ), 116-117, 228
keys, 304-305 pointers, 144-147 strcspn( ), 228
KillTimer( ), 387 pow( ), 240 stream functions, 68
ldexp( ), 240 print functions, overhead, 297 strncat( ), 226, 228
libraries, 215-241 print_document( ), 104 strncmp( ), 228
advantages, 216 print_report( ), 163-164 strncpy( ), 123-124, 226, 228
creating, 321-322 printf( ), 122-123, 128-129, strpbrk( ), 228
defining, 216-223 157, 257, 295-296, 305, 386 strrchr( ), 228
.EXE files, 320-321 prototyping, 162-163 strrev( ), 118-120
memory, 229-231 putchar( ), 295 strspn( ), 228
strings, 226-229 _putenv( ), 256 strtok( ), 228
localeconv( ), 233 qsort( ), 36-37, 73-74, strtoul( ), 127-128
localtime( ), 404 145-147 system calls, 255
locking( ), 78 rand( ), 354-356 system( ), 362-363
log( ), 239 Rectangle( ), 390 tan( ), 239
log10( ), 239 recursion, 342-344 tanh( ), 239
longjmp( ), 8-10, 233-234 return statements, 166, 271 TextOut( ), 390, 404
lseek( ), 79-80 exit( ), 171-173 time( ), 404
ltoa( ), 125 rjust( ), 120-122 timegm( ), 251
ltrim( ), 119-120 rtrim( ), 117-122 timelocal( ), 251
main( ), 45, 289-290 scanf( ), 302-303 tolower( ), 232
prototypes, 271 scope, 165 toupper( ), 232
returning values, 272 SelectObject( ), 390 ultoa( ), 125
malloc( ), 16, 149, 324 _setargv( ), 350 variable arguments, 223-225
alternative versions, setjmp( ), 8-10, 233-234 WaitMessage( ), 357
236-239 setlocale( ), 233 wcstombs( ), 241
memory leaks, 203 SetSysColor( ), 406 wctomb( ), 241
mblen( ), 241 SetTimer( ), 387 Windows compared to DOS,
mbstowcs( ), 241 SetupFilters( ), 360 392-393
mbtowc( ), 241 setvbuf( ), 294 wsprintf( ), 404
memchr( ), 228, 231 SetWindowLong( ), 409
memcmp( ), 231 SetWindowText( ), 405 G
memcpy( ), 116-117, 231 signal( ), 235 GDI (Graphic Device
memmove, 229, 231 sin( ), 239 Interface), 389-390
memrchr( ), 228 sinh( ), 239 getch( ) function, 257
memset( ), 231 some_func( ), 162-163 getche( ) function, 258
merge( ), 40, 45 sopen( ), 77-79 getenv( ) function, 76-77, 256
modf( ), 240 sort_files( ), 74 GetKeyState( ) function and
naming, 210-211, 337-338 spawn( ), 361-362 Windows, 400
camel notation, 336 split( ), 40-41, 45 GetSysColor( ) function and
Hungarian notation, sprintf( ), 121, 386 Windows, 405-406
340-341 sqrt( ), 239 GetWindowLong( ) function,
NewCommVector( ), 367 srand( ), 354-356 409
open_customer_indexes( ), stat_func( ), 160 glob_func( ) function, 160-161
global heap (Windows), 412
422 global scope

global scope, 165 stdlib.h, 236 infinite loops, 199-200


global variables, 360 string.h, 226 null loops, 345-346
declaring/defining in headers, variable declarations/ initializing variables, 16-17
27 definitions, 27 input and scanf( ), 302-303
DGROUP: group exceeds windows.h, 344 insertion sorts, 31
64K message, 323 heaps (memory), 152-153 int86( ) function, 257, 263
GlobalAlloc( ) function and far heaps, 327-329 int86x( ) function, 257, 263
Windows, 413-414 near heaps, 327-329 integers
GlobalFree( ) function and recursion, 152 converting strings to integers,
Windows, 414 strings, 152 126-128
GlobalLock( ) function and variable storage, 16 converting to strings, 124-126
Windows, 414 Windows, 412-413 mathematical operations,
GlobalUnlock( ) function and hexadecimal numbering system, 239-240
Windows, 414 380-381 integral types (mathematical
goto statements, 8-10 assigning values to variables, operations), 24
graphics 376 internal sorts, 32
changing modes (Basic Input high-order bytes, 195 interrupt 24 (critical error
Output System), 265-269 hosted vs. free-standing handler), 81
OEM (Original Equipment environments, 225 interrupt 62 (command-line
Manufacturer) key codes, Huge memory model, 317-319 parameters), 352
397-398 Hungarian notation (naming interrupting Windows
conventions), 333, 340-341 programs, 357-360, 388-389
H HWND (Windows), 394 interrupts, 263-264
.h files (#include statements), ints, 280
93 I InvalidateRect( ) function, 395
HANDLE (Windows), 394 if statements isalnum( ) function, 232
handles (Windows), 387-388 multiple if statements and isalpha( ) function, 232
hanging programs, 197-203 switch statements, 3-4 iscntrl( ) function, 232
harderr( ) function, 81-83 pointers, 143 isdigit( ) function, 232
hardresume( ) function, 81 #ifdef directive (preprocessor), isgraph( ) function, 232
hardretn( ) function, 81 112 islower( ) function, 232
hardware portability, 276 ISO (International Standards
error handling, 81-83 #ifndef directive (preprocessor), Organization), 283-291
interrupts, 263 92, 112 isprint( ) function, 232
hashing (searching algorithms), implicitly cast variables ispunct( ) function, 232
33, 55-57 (compile-time checking), isspace( ) function, 232
HDC (Windows), 394 206-207 isupper( ) function, 232
header files #include <file> compared to isxdigit( ) function, 232
ctype.h, 232 #include "file", 99 iterative processing, 341-342
declaring (variables), 271 #include statements (.h files), itoa( ) function, 124-126
defining at compile time 93
(preprocessor), 100 include files, nesting J-K
math.h, 239 (preprocessor), 100-101 jmp_buf variable, 234
redundancy (preprocessor), 92 increment operator jumping out (functions),
setjmp.h, 234 (++ operator), 13 233-235
signal.h, 235 incremented variables
standard library functions, infinite loops, 199 KbIntProc( ) function, 374
216-223 passing to macros, 88-89 Kernighan and Ritchie brace
static variable declarations, 28 indirection (pointers), 133 style, 338
stdarg.h, 223 null pointers, 135-138 Kernighan, Brian W., 353
stddef.h, 240 InDos Flag, 258 keyboard (dead keys), 400-401
main( ) function 423

KeyBoardProc( ) function, 360 algorithm, 45-48 log10( ) function, 239


keystroke processing with III.4a. bsearch( ), 49 logic checking (default cases), 5
scanf( ), 303 III.4b. Binary searches, 49-50 logical operators (operator
KillTimer( ) function and III.4c. Linear searching, 50 precedence), 286
Windows, 387 III.5. Digital trie searching, longjmp( ) function, 8-10,
51-55 233-234
L III.6. Hash algorithm, 56 longs, 280
Large memory model, 317-319 III.9. Building programs, 59 loops
ldexp( ) function, 240 III.9a. driver1.c driver , 60 break vs. continue statements,
leading spaces (strings), III.9b. driver2.c driver, 60 346
118-120 III.9c. driver3.c driver, 61-62 error handling, 209-210
leaks in memory, detecting, III.9d. list.h header file, 61-62 executing successfully, 7-8
203-204 III.9e. list.c source file, 61-62 infinite loops
letter characters, 374-375 III.9f. hash.h header file, 62 debugging, 199-200
levels of pointers, 134-135 III.9g. hash.c source file, 62 vs. null loops, 345-346
libraries, 215-241 VII.1. Indirection, 133 iterative processing, 341-342
creating, 321-322 VII.2. Circular list with nested for loops, debugging,
cursor positioning, 294 infinite indirection, 134-135 202
functions VII.7. Pointer arithmetic, null loops, 345
advantages, 216 140-141 low-order bytes, 195
defining, 216-223 VII.15. Arrays with runtime lseek( ) function, 79-80
.EXE files, 320-321 size, 147-148 ltoa( ) function, 125
memory, 229-231 X.2. Macros for handling flags, ltrim( ) function, 119-120
multiple functions in one 192 lvalues, 10-12
source file, 321 X.4. Bitshifting and
reusable functions, multiplication by 2, 195 M
321-322 XII.3. printf-like function, macros
source files, 320 223-225 BIT_POS( ), 192
strings, 226-229 XII.5a. string-n functions, 227 BIT_RANGE( ), 193
printing, 297 XII.5b. strtok, 228-229 BIT_SHIFT( ), 193
#line directive (preprocessor), XII.6. Moving data, 229 compared to functions
107-108 XII.9. setjmp( ) and (preprocessor), 98
_ _LINE_ _ preprocessor longjmp( ), 234-235 concatenation operator (##),
command, 108 XII.12. Pool allocator, 89, 101-102
linear searches, 50 237-238 #define statement, 88-89
linked lists literals (string literals), 186-187 flag handling (listing X.2), 192
recursion, 136 little-endian compared to incremented variables, passing,
searching, 57 big-endian, 280-281 88-89
sorting, 57 local blocks, 1-3 NDEBUG, 213
lint (debugging tool), 205 local scope, 165 predefined macros
listbox class (Windows), localeconv( ) function, 233 (preprocessor), 103
411-412 locales, 233 preprocessor, 88-89
listing localtime( ) function and SET_FLAG( ), 193
date and time of files, 70-72 Windows, 404 SET_MFLAG( ), 193
files in directories, 68-69 locating stringizing operator (#), 89
listings directories of executing type-insensitive macros
III.1. qsort( ), 36-37 programs, 368-369 (preprocessor), 102-103
III.2a. Quick sort, 38-40 files, 369-370 undefining (preprocessor),
III.2b. Merge sort, 41-42 locking files, 79-80 111-112
III.2c. Radix sort, 43-44 locking( ) function, 78 main( ) function, 45
III.3. External sorting log( ) function, 239 C++, 290
424 main( ) function

prototypes, 271, 289-290 leaks, 203-204 moving cursor positions (ANSI


returning values with, 272, managing, 324 driver), 313-314
290 bank switching, 326 multibyte characters, 240-241
make utilities, 322-323 disk swapping, 325 multiple if statements (switch
makefiles (sort/search sample DOS extenders, 325 statements), 3-4
code), 58 EMS (expanded memory), multiple library functions in
malloc( ) function, 324 326 one source file, 321
alternative versions, 236-239 free( ) function, 156-157 multiplication by 2 and
compared to calloc( ) near and far, 327-329 bitshifting, 194-195
function, 149 overlay managers, 324-325
memory leaks, 203 XMS (extended memory), N
variable storage, 16 326 naming
masking bits, 191-194 movable segments (Windows), functions, 210-211, 337-338
math.h header file, 239 412-413 Hungarian notation, 340-341
mathematical operations organizing (Windows), variables, 210-211, 236,
floating-point types, 24, 412-413 339-340
239-240 page thrashing, 17-18 ANSI/ISO C standard, 340
integers, 239-240 raw memory (void pointers), camel notation, 336
integral types, 24 138-139 Hungarian notation, 333
operator precedence, 286 sizing allocated memory, 156 indicating data type,
pointer types, 24 stacks, 151-152 332-333
type casts, 26 variable storage, 16 program efficiency,
variables, 24-25 memory image files, see .COM 336-337
void pointers, 157 files underscores, 332
mblen( ) function, 241 memory mapped hardware natural (sorting algorithms), 32
mbstowcs( ) function, 241 (volatile modifier), 20-21 navigating arrays with pointers
mbtowc( ) function, 241 memory models, 317-319 or subscripts, 181-183
Medium memory model, memrchr( ) function, 228 NDEBUG macro, 213
317-319 memset( ) function, 231 near compared to far, 327-329
memchr( ) function, 228, 231 merge sorts, 32, 40-42 near pointers compared to far
memcmp( ) function, 231 merge( ) function, 40, 45 pointers, 150-151
memcpy( ) function, 231 MMU (Memory Management nested for loops, debugging,
compared to strcpy( ), Unit), 17 202
116-117 modal and modeless dialog nesting include files
memmove( ) function, 229, 231 boxes, 414 (preprocessor), 100-101
memory modf( ) function, 240 network byte order, 281
allocating, 132-158 modular programming, 316 NewCommVector( ) function,
calloc( ), 149 modulus operator (%), 14 367
malloc( ), 149 monetary values, printing, nibbles (binary numbering),
memory leaks, 203 307-309 378
pool allocators, 237, 239 monitor programs, writing text non-English characters, see
recursion, 343 to the screen, 297 multibyte characters
Windows, 413 Motherboard BIOS, 262 nonzero numbers (errno
data transfer, 363-368 mouse variable), 63-64
DOS locations, 260-262 click capturing (Windows), null loops vs. infinite loops,
dynamic memory allocation, 402-403 345-346
324 controlling (BIOS), 272-273 null pointers, 135-138
faults, 155-156 interrupt services, 272 assignment errors, 155-156
fixed segments (Windows), Windows, 401-402 null terminators (strings), 306
412-413 movable segments (Windows),
heaps, 152-153 412-413
preprocessor 425

NULLs overflow errors near pointers, 150-151


compared to NULs, 155 (string conversion), 127-128 null pointers, 135-138
defining as 0, 142 overhead (print functions), 297 NULLs compared to NULs,
numbers overlay managers (memory 155
binary numbering, 377-379 management), 324-325 portability, 133
characters, 375-376 overriding defined macros subtracting, 139-141
converting strings to numbers, (preprocessor), 111-112 to const, 18-19
126-128 void pointers, 138-139
converting to strings, 124-126 P writing data to the screen, 298
doubles, 308 packages, printing, 297 pool allocators, 237, 239
floats, 308 padding strings to fixed lengths, portability, 275-281
hexadecimal numbering, 122-123 // for comments in C, 279
380-381 page faults, 17 big-endian compared to
octal numbering, 377, 379 page thrashing, 17-18 little-endian, 280-281
scientific notation, 310 paging out, 17 bit fields, 194
variables, maximum values of, parameters (functions), 163-165 C++ compiler additions in C
23-24 parentheses (operator programs, 277
zero-padding, 307 precedence), 286 chars, 280
pascal calling convention #ifdefs, 276
O (Windows functions), 392 ints, 280
object-oriented design (C and PASCAL-declared functions, longs, 280
C++), 278 170-171 pointers, 133
octal values, 379 passing shorts, 280
assigning to numbers, 377 arrays to functions, 167-169 time standards, 251
OEM (Original Equipment data, 363-368 postfix operations, 13-14
Manufacturer) key codes, incremented variables to operator precedence, 285
397-398 macros, 88-89 pow( ) function, 240
offset (addresses), 178 PATH environment variable, #pragma directive
open addressing (collisions), 55 viewing, 76-77 (preprocessor), 106-107
open_customer_indexes( ) PeekMessage( ) function, 357 predefined macros
function, 165-166 PMM (Process Memory Map), (preprocessor), 103
open_customer_table( ) 17 prefix operations, 13-14
function, 165-166 pointers, 132-158 operator precedence, 285
operator precedence, 12-13, adding, 143-144 preprocessor, 87-113
269-271, 284-287 adding values to, 141-142 ANSI C standard, 110-111
assignment operators, 287 arithmetic (listing VII.7), commenting out code, 98-99
associativity, 270-271 140-141 compile date and time,
bitwise shifting, 286 arrays, 180 printing, 110
comma operators, 287 binary searches, 139 concatenation operator (##),
conditional expressions, 287 callback (function pointers), 101-102
equality comparisons, 286 145 conditional compilation, 91
logical operators, 286 far pointers, 150-151, 298 constant declarations
mathematical expressions, 286 freeing pointers twice, #decline, 93-94
parentheses, 286 153-154 enum, 94
postfix expressions, 285 functions, 144-147 _ _DATE_ _ preprocessor
prefix expressions, 285 if statements, 143 command, 109-110
relational comparisons, 286 indirection, 133 #define directive, 92
x=y=z, 287 levels of pointers, 134-135 use with true/false, 344
operator promotion, 25-26 mathematical operations, 24 demo programs, disabling, 97
output, 293-294 memory models, 132 error locations, printing, 104
navigating arrays, 181-183 _ _FILE_ _ preprocessor
command, 108
426 preprocessor

header files error locations (preprocessor), speed of execution


defining at compile time, 104 searching algorithms,
100 file attributes, 75-76 33-35, 50-55
redundancy, 92 libraries, 297 sorting algorithms, 33-35,
#ifdef directive, 112 packages, 297 37-44
#ifndef directive, 92, 112 PATH environment variable, writing, 315-329
#include <file> compared to 76-77 prototyping
#include "file", 99 redirection (stdout), 66-67 functions, 162-163
#include statements (.h files), scientific notation, 310 main( ) function, 271,
93 source files 289-290
include files, nesting, 100-101 errors, 105 pseudo-random number
#line directive, 107-108 line numbers, 109 generators, 354-356
_ _LINE_ _ preprocessor names, 108 PSPs (Program Segment
command, 108 string sections, 128-129 Prefixes) and command-line
macros, 88-89 Process Memory Map (PMM), parameters, 349-351
compared to functions, 98 17 putchar( ) function, 295
#pragma directive, 106-107 Program Segment Prefixes _putenv( ) function, 256
predefined macros, 103 (PSPs) and command-line
programs, 90-92 parameters, 349-351 Q-R
source files, printing programs qsort( ) function, 36-37, 73-74,
errors, 105 compiling, 315-329 145-147
line numbers, 109 conventions, 233 quick sort, 38-40
names, 108 Ctrl-Break (stopping
symbolic constants, 91 execution), 300-301 radix searching, 33
symbols, checking for data transfer, 363-368 radix sort, 32, 43-44
definition, 112 debugging, 197-213 rand( ) function, 354-356
_ _TIME_ _ preprocessor failed conditions, 212-213 random number generation,
command, 109-110 methods, 204-211 354-356
type-insensitive macros, tools, 205-207 ranges and date variables, 244
102-103 TSR (terminate-and-stay- raw memory (void pointers),
preventing errors, 208-211 resident) programs, 138-139
print functions (overhead), 297 211-212 Rectangle( ) function, 390
print_document( ) function, directories of executing recursion, 342-344
104 programs, 368-369 heaps, 152
print_report( ) function, efficiency, 333-336 linked lists, 136
163-164 fitting to DOS, 324-325 null pointers, 136-138
printf( ) function, 122-123, hanging programs, 197-203 redirection
128-129, 157, 257 debugging, 198-199 printing stdout, 66-67
executables, 296 excessive execution time, standard streams, 65-66
Windows, 386 200-202 refreshing windows, 395-396
writing data to the screen, infinite loops, 199-200 register modifier, 19-20
295-296, 305 waiting for input, 202-203 relational comparisons
printing interrupting (Windows), (operator precedence), 286
addresses, 157-158 357-360 repainting client areas
AUTOEXEC.BAT file, 341 modular programming, 316 (Windows), 395-396
color characters to screen, 260 preprocessor, 90-92 residency checks (data transfer),
compile date and time sequential execution, 361-362 368
(preprocessor), 110 simultaneous execution, resource editors (buttons and
dollars-and-cents values, 362-363 controls), 407
307-309 restoring
spawn( ) function 427

cursor positions (ANSI driver), digital trie, 50-55 sizeof operator (arrays),
312 hashing, 33, 55-57 179-180
redirected standard streams, linear searching, 50 sizing
65-66 linked lists, 57 allocated memory, 156
retrieving environment radix searching, 33 arrays
variables, 256-257 sample codes, 57-62 at runtime, 147-148
Retry message, 81-83 sequential searching, 33 constant values, 185
return statements speed of execution, 33-35, client areas (Windows),
exit( ) function, 171-173 50-55 396-397
void functions, 166 secondary data storage (sorting Small memory model, 317-319
return( ) function, 271 algorithms), 44-48 Software Development Kit
returning values with segmented architecture, 179 (SDK)
main( ), 290 selection sorts, 32 C++, 392
reusable functions (libraries), SelectObject( ) function, 390 Windows, 391-392
321-322 sentinel values (null pointers), software interrupts, 263
RGB values (Windows system 137-138 some_func( ) function, 162-163
colors), 406 sequential searching, 33 sopen( ) function, 77-79
right-justification of strings, _setargv( ) function, 350 sort_files( ) function, 74
120-122 SET_FLAG( ) macro, 193 sorting
Ritchie, Dennis M., 353 SET_MFLAG( ) macro, 193 date variables, 245
rjust( ) function, 120-122 setjmp( ) function, 8-10, filenames in directories, 73-74
rtrim( ) function, 117-122 233-234 linked lists, 57
running programs setjmp.h header file, 234 sorting algorithms, 31-32
sequentially, 361-362 setlocale( ) function, 233 complexity, 33-34
simultaneously, 362-363 SetSysColor( ) function and distribution sorts, 32
rvalues, 12 Windows, 406 exchange sorts, 32
SetTimer( ) function and external sorts, 32, 44-48
S Windows, 387 insertion sorts, 31
saving setting internal sorts, 32
cursor positions (ANSI driver), breakpoints, 205 merge sorts, 32, 40-42
311-312 watches, 205 natural, 32
windows, 395-396 SetupFilters( ) function, 360 qsort( ) function, 36-37
scan statements (strings), 306 setvbuf( ) function, 294 quick sorts, 38-40
scanf( ) function, 302-303 SetWindowLong( ) function, radix sorts, 43-44
scientific notation, printing, 409 sample codes, 57-62
310 SetWindowText( ) function, selection sorts, 32
scope (functions), 165 405 speed of execution, 33-35,
screens shared files, 79-80 37-44
clearing with the ANSI driver, shared memory (volatile stable, 32
311 modifier), 20-21 source code
color (ANSI driver), 312 shared mode (opening files), comments, 334
output, 293-294 77-79 modular programming, 316
SDK (Software Development shorts, 280 source files
Kit) signal handlers, 235 errors, printing, 105
C++, 392 signal( ) function, 235 library functions, 320
Windows, 391-392 signal.h header file, 235 line numbers, printing, 109
searching algorithms, 32-33 signals, 235-236 multiple library functions, 321
binary searching, 49 disabling Ctrl-Break, 371-372 names, printing, 108
bsearch( ) function, 48-50 sin( ) function, 239 writing programs, 316
comparison searching, 33 sinh( ) function, 239 spaces in strings, 129
complexity, 33-34 spawn( ) function, 361-362
428 speed of execution

speed of execution time variables, 248-253 scan statements, 306


searching algorithms, 33-35, variables, 16 spaces, 129
50-55 in local blocks, 3 trailing spaces, 117-118, 129
sorting algorithms, 33-35, strcat( ) function, 228 strncat( ) function, 226, 228
37-44 strchr( ) function, 228 strncmp( ) function, 228
split( ) function, 40-41, 45 strcmp( ) function, 37, strncpy( ) function, 123-124,
sprintf( ) function, 121 129-130, 146-147, 228 226, 228
Windows, 386 strcoll( ) function, 233 strpbrk( ) function, 228
sqrt( ) function, 239 strcpy( ) function, 228 strrchr( ) function, 228
srand( ) function, 354-356 compared to memcpy( ), strrev( ) function, 118-120
stable (sorting algorithms), 32 116-117 strspn( ) function, 228
stacks (memory), 151-152 strcspn( ) function, 228 strtok( ) function, 228
variable storage, 16 streams, 64, 68 strtoul( ) function, 127-128
standard display modes, 267 binary streams, 67 structured exception handling,
standard library functions, redirecting, 65 352
215-241 restoring redirected standard subclassing windows, 409
advantages, 216 streams, 65-66 subscripts (arrays), 176-177
defining (header files), scanf( ) function, 302 navigating arrays, 181-183
216-223 stdaux, 64 subtracting pointers, 139-141
memory, 229-231 stderr, 64 switch statements, 3-5
strings, 226-229 stdin, 64 symbolic constants
standard predefined macros stdout, 64 compared to enumerated
(preprocessor), 103 print redirection, 66-67 constants, 95-96
standard streams, 65-66 stdprn, 64 preprocessor, 91
standards text streams, 67 symbolic debuggers
ANSI, 283-291 string literals, 186-187 (enumerated constants), 96
ISO, 283-291 string.h header file, 226 symbols, checking for definition
time, 251 stringizing operator (#) and (preprocessor), 112
stat_func( ) function, 160 macros, 89 system calls, 255
statements, break and continue, strings, 116-130 system colors (Windows),
346 compared to arrays, 186-187 405-407
static child windows, 408 comparing, 129-130, 228 system( ) function, 362-363
static functions, 165-166 concatenating, 228
static scope, 165 converting T
static variables, 360 numbers to strings, tags, array (addressing),
declaring in headers, 28 124-126 183-184
stdarg.h header file, 223 to numbers, 126-128 tan( ) function, 239
stdaux stream, 64 copying, 228 tanh( ) function, 239
_ _STDC_ _ (ANSI C sections of, 123-124 terminate-and-stay-resident
standard), 110-111 heaps, 152 programs, see TSR programs
stddef.h header file, 240 leading spaces, 118-120 terminating Windows
stderr stream, 64 manipulating, 226-229 programs, 388-389
stdin stream, 64 multibyte characters, 241 termination handling
stdlib.h header file, 236 null terminators, 306 (try-finally statement), 352
stdout stream, 64 overflow errors (converting text
print redirection, 66-67 strings to numbers), 127-128 animated text, 296
stdprn stream, 64 padding strings to fixed color
storing lengths, 122-123 ANSI driver, 312-313
data, 16-29 printing string sections, writing data to the screen,
date variables, 243-247, 252 128-129 298-300
flags, 190-191 right-justification, 120-122 comma-delimited text, 83-85
Windows 429

formatted text, 295 undefining macros register modifier, 19-20


monitor programs, 297 (preprocessor), 111-112 static variables, 360
writing to the screen, 296-300 underscores storing, 16
text editors (writing text to the camel notation, 336 in local blocks, 3
screen), 296 variable names, 236, 332 time, 243-253
text mode compared to binary uninitialized variables uninitialized variables
mode, 67 (compile-time checking), 206 (compile-time checking),
text streams, 67 unsigned variables (infinite 206
TextOut( ) function, 390, 404 loops), 200 volatile modifier, 20-21
_ _TIME_ _ preprocessor updating title bars (Windows), watching, 205
command, 109-110 405 VESA (Video Electronics
time and date, 70-72 Standards Association),
compile time and date V 268-269
(preprocessor), 110 values, returning with main( ), BIOS standard, 266-267
Windows, 404 272, 290 VGA cards, 268
time variables, 243-253 var++ compared to ++var, 13-14 VGA graphics modes, changing,
time( ) function and Windows, variables, 16-29 265-269
404 arguments (functions), Video BIOS, 265
timegm( ) function, 251 223-225 virtual key codes (Windows),
timelocal( ) function, 251 const modifier, 21-22 398-400
timer events (animated date, 243-253 virtual memory (page
bitmaps), 403 declaring, 28, 271 thrashing), 17-18
timers (Windows), 387 in headers, 27 void pointers, 138-139
Tiny memory model, 317-319 defining, 28 arithmetic operations, 157
title bars, updating (Windows), in headers, 27 raw memory, 138-139
405 environment variables, return statements, 166
tolower( ) function, 232 retrieving, 256-257 type casts, 26
tools for debugging, 205-207 global variables, 360 volatile declarations, 20-21
toupper( ) function, 232 hexadecimal value const variables, 21
trailing spaces (strings), assignments, 376 type casts, 27
117-118, 129 implicitly cast variables
transferring data, 363-368 (compile-time checking), W
transistors (base 2-binary), 206-207 WaitMessage( ) function, 357
377-379 initializing, 16-17 warm boots (Ctrl-Alt-Delete),
true/false, defining, 344-345 jmp_buf, 234 disabling, 372-374
try-except statement (exception local blocks, 2 watches, setting, 205
handling), 352 mathematical operations, wcstombs( ) function, 241
try-finally statement 24-25 wctomb( ) function, 241
(termination handling), 352 naming, 210-211, 236, while loops (infinite loops), 200
TSR 339-340 white space (program effi-
(terminate-and-stay-resident) ANSI/ISO C standard, 340 ciency), 334-336
programs camel notation, 336 Whitesmiths brace style, 339
data transfer, 364-368 Hungarian notation, Win32s (32-bit compilers), 356
debugging, 211-212 340-341 WINDIR environment variable,
type casts, 26-27 indicating data type, 256
type-insensitive macros 332-333 Windows, 385-414
(preprocessor), 102-103 program efficiency, animated bitmaps, 403
336-337 buttons, 407-408
U underscores, 332 CallWindowProc( ) function,
ultoa( ) function, 125 numeric variables, maximum 409
values of, 23-24
430 Windows

carets compared to cursors, heaps, 412-413 refreshing, 395-396


401-402 HWND, 394 saving, 395-396
child window controls, 407 interrupting programs, subclassing, 409
command-line parameters, 357-360, 388-389 windows.h, 344, 390-391
350 KillTimer( ) function, 387 WINSTUB.EXE (Windows
compiler compatibility, listbox class, 411-412 SDK), 391
394-395 localtime( ) function, 404 WM_PAINT message
controls, 407-408 memory (Windows), 395-396
cooperative multitasking, 357 allocating, 413 WM_SIZE message (Windows),
CreateDialog( ) function, 414 organizing, 412-413 396-397
CreateWindow( ) function, modal and modeless dialog writing
388 boxes, 414 data to the screen, 295-296
edit class, 410-411 mouse programs, 315-329
listbox class, 411-412 clicks, capturing, 402-403 text to the screen, 296-300
date and time, 404 positioning, 401-402 wsprintf( ) function, 404
dead keys, 400-401 movable segments, 412-413
DefWindowProc( ) function, OEM (Original Equipment X-Y-Z
402 Manufacturer) key codes, x=y=z (operator precedence),
delay timers, 387 397-398 287
device contexts, 386 pascal calling convention, 392 XMS (extended memory), 326
DialogBox( ) function, 414 printf( ) function, 386
DLLs (dynamic link libraries), repainting client areas, zero bits and calloc( ), 149
393 395-396 zero-padding numbers, 307
edit class, 410-411 resource editors (buttons and
editing position, 401-402 controls), 407
environment variables SDK (Software Development
(WINDIR), 256 Kit), 391-392
FAR PASCAL declarations, SetSysColor( ) function, 406
392 SetTimer( ) function, 387
filter functions (interrupting SetWindowLong( ) function,
programs), 357-360 409
fixed segments, 412-413 SetWindowText( ) function,
functions compared to DOS, 405
392-393 sizing client areas, 396-397
GDI (Graphic Device sprintf( ) function, 386
Interface), 389-390 static child windows, 408
GetKeyState( ) function, 400 subclassing windows, 409
GetSysColor( ) function, system colors, 405-407
405-406 time( ) function, 404
GetWindowLong( ) function, title bars, updating, 405
409 virtual key codes, 398-400
global heap, 412 windows, saving and
GlobalAlloc( ) function, refreshing, 395-396
413-414 windows.h, 390-391
GlobalFree( ) function, 414 WINSTUB.EXE, 391
GlobalLock( ) function, 414 WM_PAINT message,
GlobalUnlock( ) function, 414 395-396
HANDLE, 394 WM_SIZE message, 396-397
handles, 387-388 windows
HDC, 394 HWND (handle), 394

Você também pode gostar