Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Advanced C 1992

.pdf
Скачиваний:
92
Добавлен:
17.08.2013
Размер:
4.28 Mб
Скачать

Advanced C

#ifdef directive, 630-631 #ifndef directive, 631-632

in-memory data object, see indexed files, 321

#include directive, 629 include files, see header files incrementing pointers, 67 INDEX.C program, 368-382 indexed files, 321, 367, 383 indexes

array, saving, 389 in disk files, 390

indexing

arrays, 48, 52-54 pointers, 89

indirection, 65, 69 initializing

single-dimensional arrays, 52 structures, 192

variables, 15, 35-36 inline assembly, 669 inp( ) function, 288 input filename, 112 input/output (I/O), 249

base address, 296 console, 280-281, 287 direct port, 288-289 files, 250-251 functions, 90 high-level, 278 low-level, 278-280 port, 280-281, 287 video direct, 667

inpw( ) function, 288

Insert() function, 395, 420-421 insertion operators, 698

instructions

80x86 set, 671-672 Int 21, 455

Int 21 instruction, 455 int constants, 26

int data type, 20 int keyword, 9

INT_MAX identifier, 22, 509 INT_MIN identifier, 22, 509 integers

overflow, 31 storing, 151-154 variables, 30

Intel Code Builder product, 658 interface cards, 288

interfaces DPMI, 658 user, 162

interfacing with dBASE, 468 interrupt enable register, 300 interrupt identifier register, 300 intrinsic functions, 664-666, 672 io.h header file, 508

IOFBF mode, 573 IOLBF mode, 573 IONBF mode, 573

isalnum() function, 503, 547 isalnum(_c) macro, 503 isalpha() function, 502, 547 isalpha(_c) macro, 503 iscntrl() function, 503, 547 iscntrl(_c) macro, 503 isdigit() function, 502, 548 isdigit(_c) macro, 503 isgraph() function, 503, 548 isgraph(_c) macro, 503 islower() function, 502, 549

758

Index

C C C

 

CCC

 

C

C

C

islower(_c) macro, 503 isprint() function, 503, 549 isprint(_c) macro, 503 ispunct() function, 502, 549 ispunct(_c) macro, 503 isspace() function, 502, 550 isspace(_c) macro, 503 isupper() function, 502, 551 isupper(_c) macro, 503 isxdigit() function, 502, 551 isxdigit(_c) macro, 503 _item structure, 416

J—K

jumpbuffer parameter, 555, 570 JUSTIFY.C program, 103-109,

136-137

kbhit() function, 281 key parameter, 527 keywords

auto, 7 break, 8 case, 8 char, 8 const, 7 continue, 8 default, 8 do, 8 double, 8 else, 8 enum, 8

extern, 8, 40, 164 float, 8

for, 9

FORTRAN, 7 _ _fortran, 450 goto, 9

if, 9 int, 9 long, 9

PASCAL, 7 register, 9 reserved, 7-10 return, 9 short, 9 signed, 7 sizeof, 9 static, 9

struct, 9, 191-194 switch, 10 typedef, 10, 208 union, 10 unsigned, 10 void, 10

volatile, 7 while, 10

L

L_tmpnam identifier, 266 labs() function, 551 languages

assembly, 438

calling C functions, 451, 455 calling from C, 447

inline, 669 routine types, 437

BASIC, 437, 443 C

calling other languages from, 443, 447-450

759

Advanced C

compilers, see compilers portability, 4

power of, 4 routine types, 437 standards, 3

C++, 695

classes, 714-715 declaring variables, 704

default parameter values, 706 overloading functions, 701-702 reference variables, 710

return values, 711 combining, 435-436

data type compatibility, 463-465 naming considerations, 465 problems, 462-463

FORTRAN, 435, 441 calling C functions, 462 calling from C, 449-450 routine types, 437

Pascal, 442

calling C functions, 462 calling from C, 449-450 routine types, 437

Large memory model, 674 LC_ALL category, 572 LC_ALL identifier, 509 LC_COLLATE category, 572 LC_COLLATE identifier, 509 LC_CTYPE category, 572 LC_CTYPE identifier, 509 LC_MONETARY category, 572

LC_MONETARY identifier, 509 LC_NUMERIC category, 572 LC_NUMERIC identifier, 510 LC_TIME identifier, 510 LDBL_DIG constant, 507

LDBL_DIG identifier, 24 LDBL_EPSILON constant, 507 LDBL_EPSILON identifier, 24 LDBL_MANT_DIG constant, 507 LDBL_MANT_DIG identifier, 24 LDBL_MAX constant, 507 LDBL_MAX identifier, 24 LDBL_MAX_10_EXP constant, 507 LDBL_MAX_10_EXP identifier, 25 LDBL_MAX_EXP constant, 508 LDBL_MAX_EXP identifier, 25 LDBL_MIN constant, 508 LDBL_MIN identifier, 25 LDBL_MIN_10_EXP constant, 508 LDBL_MIN_10_EXP identifier, 25 LDBL_MIN_EXP constant, 508 LDBL_MIN_EXP identifier, 25 LDBL_RADIX identifier, 25 LDBL_ROUNDS identifier, 25 ldexp( ) function, 552

ldiv( ) function, 552 left side, 393

lFieldPointer member, 473 LIB utility, 182

libraries, 165 creating, 182 mLIBC7.LIB, 668 mLIBCA.LIB, 668 mLIBCE.LIB, 668

reserved names, 10-11 LIFETIME.C program, 40-41 limits.h header file, 508-509 line control register, 301

line dependency, 184 #line directive, 634-635

line numbers, modifying, 634 line status register, 301

760

Index

C C C

 

CCC

 

C

C

C

linear searches, 345, 367, 383-384 link commands, 165

linked lists, 344-345 disk-based, 346 double, 346-347 dynamic memory, 345 linear searches, 367

linking

for performance, 670-671 multifile programs, 164-165 multiple source files, 162-163

LINKLIST.C program, 347-359 list pointers, 346

Listing 1.1. External name lengths for FILEONE.C and FILETWO.C, 6

Listing 1.2. HELLO.C, 14-15

Listing 1.3. A typical source file header block, 16-17

Listing 2.1. BADSTR.C, 27-29 Listing 2.2. An example of a global

variable, in a single source file, 32 Listing 2.3. An example of a global

variable, in three source files, 33-34 Listing 2.4. SCOPE.C, 37

Listing 2.5. SCOPE1.C, 38-39 Listing 2.6. LIFETIME.C, 40-41 Listing 2.7. CASTS.C, 42-44 Listing 2.8. ARRAY1.C, 49-51 Listing 2.9. ARRAY2.C, 55-56 Listing 2.10. REPEAT.C, 59-60 Listing 3.1. POINTERS.C, 69-71 Listing 3.2. The output from

POINTERS.C, 72

Listing 3.3. ADDER.C, 72-74 Listing 3.4. NUMWORD.C, 76-77 Listing 3.5. NUMWORD1.C, 79-81

Listing 3.6. NUMWORD3.COD, the assembly listing for the pointer version

of NumberWords( ), 82-85

Listing 3.7. NUMWORD4.COD, the assembly listing for the array indexed version of NumberWords( ), 85-89

Listing 3.8. FIXSTR.C, 92-94 Listing 3.9. RAGSTR.C, 95-96 Listing 4.1. MAINARGS.C, 101-102 Listing 4.2. JUSTIFY.C, 103-109 Listing 4.3. FUNPTR.C, 115-117 Listing 4.4.MENU1.C, 121-129 Listing 4.5. State machine from

JUSTIFY.C, 136-137

Listing 5.1. DUMP.C, 146-150 Listing 5.2. WCHBYTE.C, 152-153 Listing 6.1. An example of a main

include file for a large project, 167 Listing 6.2. An example of the defines.h

include file, 167

Listing 6.3. An example of the typedef.h include file, 168-169

Listing 6.4. An example of the vars.h include file, 169-170

Listing 6.5. An example of the prototyp.h include file, 170

Listing 6.6. TWOFILE1.C, 171-175 Listing 6.7. TWOFILE2.C, 176-178 Listing 6.8. TWOFILE.H, 178 Listing 6.9. DEFINE.H, 179 Listing 6.10. TYPEDEF.H, 180 Listing 6.11. VARS.H, 180

Listing 6.12. PROTOTYP.H, 180-181 Listing 6.13. TWOFILE.MAK, a

MAKE file to compile TWOFILE, 183

Listing 6.14. TWOFILE, an advanced MAKE file for the TWOFILE program, 184-186

Listing 7.1. STRUCT1.C, 193-194

761

Advanced C

Listing 7.2. STRUCT2.C, 195-197 Listing 7.3. STRUCTA.C, 198-199 Listing 7.4. STRUCT3.C, 200-202 Listing 7.5. STRUCT4.C, 203-205 Listing 7.6. CREATEDB.C, 209-212 Listing 7.7. OFFSETOF.C, 213-215 Listing 7.8. STRUPTR.C, 216-219 Listing 7.9. UNION.C, 220-225 Listing 8.1. MALLOC2.C, 230-231 Listing 8.2. CALLOC1.C, 233-235 Listing 8.3. CDB.C, 238-243

Listing 8.4. SORTALOC.C, 244-246 Listing 9.1. TEXTFILE.C, 252-256 Listing 9.2. EDLINE.C, 257-266 Listing 9.3. STDAUX.C, 273-274 Listing 9.4. STDPRN.C, 275-276 Listing 9.5. STDFILE.C, 276-278 Listing 9.6. ARCADE.C, 282-287 Listing 9.7. PRNPORT.C, 289-295 Listing 9.8. SENDCOMM.C, 301-308 Listing 9.9. READCOMM.C, 309-317 Listing 10.1. SORTFILE.C, 323-326 Listing 10.2. MERGFILE.C, 330-334 Listing 10.3. PURGFILE.C, 336-341 Listing 10.4. LINKLIST.C, 347-359 Listing 10.5. INDEX.C, 368-382 Listing 10.6. BTREE.C, 395-415 Listing 11.1. CALLASM.ASM,

439-440

Listing 11.2. DEMO.FOR, 441 Listing 11.3. HELLO.PAS, 442 Listing 11.4. HELLO.BAS, 443 Listing 11.5. CALLNOTC.C, 443-446 Listing 11.6. MAXIMUM.ASM,

447-448

Listing 11.7. The maximum() function in FORTRAN, 449

Listing 11.8. MAXIMUM.C, 450-451

Listing 11.9. CALLNOTC.ASM, 452-455

Listing 12.1. DBREAD.C, 474-482 Listing 12.2. DBWRITE.C, 484-493 Listing 13.1. VARGS.C, 513-515 Listing 15.1. MACROS.C, 625-628 Listing 16.1. ASSERT.C, 651

Listing 16.2. DBGSTRNG.C, 652-654 Listing C.1. HELLOCPP.CPP—A first

C++ program, 697

Listing C.2. EXAMP1.CPP—A C++ program with both input and output, 700

Listing C.3. EXAMP2.CPP—Program showing C++ function overloading, 702-704

Listing C.4. EXAMP3.CPP—Program showing variable declaration in a statement, 705

Listing C.5. EXAMP4.CPP—Program showing default values for arguments, 706-709

Listing C.6. EXAMP5.CPP—Program showing a reference variable, 710-711 Listing C.7. EXAMP6.CPP—Program showing a reference variable, 712-713 Listing C.8. EXAMP7.CPP—Program

showing C++ classes, 715-718 lists, linked, 344-345

disk-based, 346 double, 346-347 dynamic memory, 345 linear searches, 367

literals, character, 623 lNumberRecords variable, 471 local

memory, 247 scope, 31

762

Index

C C C

 

CCC

 

C

C

C

Locale parameter, 571 locale.h header file, 509-510

localeconv() function, 510, 553 localtime() function, 553 lOffset parameter, 542

log() function, 554 log10() function, 554

LOGICAL_FIELD identifier, 472 long double-floating-point constants,

27

long int constants, 26 long keyword, 9 long modifier, 20

LONG_MAX identifier, 22, 509 LONG_MIN identifier, 22, 509 longjmp() function, 512, 554 loop optimization, 663-664 low-level I/O, 278-280 _LOWER identifier, 502

LSB (baud rate divisor register), 300 lseek() function, 279

lValue parameter, 552

M

machines, state, 135-136

macro continuation operator (\), 622 macros

_ _DATE _ _, 637

_ _FILE _ _, 638 _ _isascii(_c), 504 _ _LINE _ _, 638 _ _STDC _ _, 638 _ _TIME _ _, 637 _ _toascii(_c), 504 _tolower(_c), 504 _toupper(_c), 504

assert(), 501, 650-652

converting to strings, 622 defining, 625 isalnum(_c), 503 isalpha(_c), 503 iscntrl(_c), 503 isdigit(_c), 503 isgraph(_c), 503 islower(_c), 503 isprint(_c), 503 ispunct(_c), 503 isspace(_c), 503 isupper(_c), 503 isxdigit(_c), 503 multiple line, 622 NULL, 638

offsetof(), 213-216, 515, 638 redefining, 637

side effects, 644 tolower(_c), 504 toupper(_c), 504 see also, identifiers

MACROS.C program, 625-628 main() function, 100 MAINARGS.C program, 101-102 MAKE files, 182-184

malloc() function, 228-232, 556 Microsoft C, 228

rules, 228

malloc.h header file, 510 MALLOC2.C program, 230-231 managers, object library, 181-182 map files, 165

math.h header file, 510 maximum() function, 445, 449

MAXIMUM.ASM program, 447-448 MAXIMUM.C program, 450-451 MB_LEN_MAX identifier, 22, 508 mblen() function, 556

763

Advanced C

mbstowcs() function, 557 mbtowc() function, 557 Medium memory model, 673 Member parameter, 563 members

byDecimalPlace, 473 byLength, 473 lFieldPointer, 473 nFirstRecordOffset, 484

memchr() function, 511, 558 memcmp() function, 511, 558 memcpy() function, 511, 559 memmove() function, 511, 560 MEMO_FIELD identifier, 472 memory

allocation, 516 breakpoints, 655 dynamic, 227, 345 global, 247

local, 247

models, 17-18, 673 Compact, 673 Huge, 674 Large, 674 Medium, 673 Small, 673 Tiny, 673

memory modification, 655 memory.h header file, 511 memset() function, 229, 511, 561 MENU1.C program, 121-129 menus, relationship to pointers,

120-121

MERGFILE.C program, 330-334 merging files, 321, 329, 343-344 message pragma, 635

Microsoft C

calloc() function, 232

free() function, 235 malloc( ) function, 228 realloc() function, 237-238

Microsoft C/C++ compiler, see C/C++ compiler

Microsoft Windows 3.1, 658 Microway NDP C/C++ compiler, 659 mktime() function, 561 mLIBC7.LIB (Coprocessor Library),

668

mLIBCA.LIB (Alternate Math Package Library), 668

mLIBCE.LIB (Emulator Library), 668 Mode parameter, 537

models, memory, 17-18, 673 Compact, 673

Huge, 674

Large, 674 Medium, 673 Small, 673 Tiny, 673

modem control register, 301 MODEM status register, 301 modes

file opening, 538 IOFBF, 573 IOLBF, 573 IONBF, 573

modf() function, 562 modification

memory, 655 program, 656

modifiers const, 25 data type

long, 20 short, 20

764

Index

C C C

 

CCC

 

C

C

C

unsigned, 20 static, 40

modifying functions, 428 line numbers, 634

modules, object, 181

MS-DOS function codes, 456-461 MSB (baud rate divisor register), 300 multibyte characters, 517

multifile programs compiling, 164 linking, 164-165

multiline macros, 622

N

n field, 618 n fields, 610 names

array, 68 external, 6

reserved library, 10-11 nBase parameter, 591-592 nBufferSize parameter, 581 nByte parameter, 561 nChar parameter, 565 nCharacter parameter, 539

nclude files, see header files, 497 nColumnCount variable, 483 nConditional parameter, 524

nCount parameter, 528, 557, 584-585, 605

nCurrentParameter variable, 112 NDEBUG identifier, 501

near identifier, 500 near pointers, 17 nError parameter, 581 nested testing, 633

NewItem() function, 395, 423 newline character, 251 nException parameter, 566 nExitCode parameter, 532 nExponent parameter, 541 nFirstRecordOffset member, 484 nFirstRecordOffset variable, 471 nLength parameter, 558-561, 593 nLineWidth variable, 113 nMode parameter, 572 nNewSize parameter, 567

nodes, 393 creating, 423 root, 393, 420

nOrigin parameter, 542 normal file attribute, 250 notation, Hungarian, 13 nRecordLength variable, 471 nReturnCode parameter, 555 nSeed parameter, 576 nSignal parameter, 574 nSize parameter, 528, 572 NULL macro, 638

NULL pointers, 345 num parameter, 527 number systems

binary, 141-142 decimal, 139-141 hex, 142-144 octal, 144-145

NumberElements parameter, 540, 544, 566

numbers

line, modifying, 634 random, 516

NumberWords( ) function, 78, 81 numerator parameter, 531, 552 NUMERIC_FIELD identifier, 472

765

Advanced C

NUMWORD.C program, 76-77 NUMWORD1.C program, 79-81 NUMWORD3.COD program, 82-85 NUMWORD4.COD program, 85-89 nValue parameter, 522

O

o fields, 610-611, 615 OBJ files, 165

object library managers, 181-182 object modules, 181

object-oriented programming (OOP), 696

abstraction, 696 encapsulation, 696-697 hierarchies, 697

octal number system, 144-145 offsetof() function, 562

offsetof() macro, 213-216, 515, 638 OFFSETOF.C program, 213-215 offsets, 17

one’s complement operator (~), 157 OOP (object-oriented programming),

696

abstraction, 696 encapsulation, 696 hierarchies, 697

open() function, 279

OpenFile parameter, 533-545, 565, 569, 572, 598, 601

operating environments, 162 operators

# (stringsize), 622-623 ## (token paste), 624 #@ (characterize), 623

&, 66, 154 *, 69 <<, 154 =, 74

= (assignment), 643 == (equality), 643 >>, 154 \, 622 ^, 154 |, 154 ~, 154

bit, 154-155 defined( ), 624 insertion, 698 precedence, 645-648

optimization

common subexpression, 666-667 compiler, 660-662 floating-point, 667-669

loop, 663-664 options

/Fa, 437 /Fc, 437 /Fl, 437 /FPa, 668 /FPc, 668 /FPc87, 668 /FPi, 669 /FPi87, 669 /S, 437

origin points SEEK_CUR, 543 SEEK_END, 543 SEEK_SET, 543

OS/2 V2 product, 658 OS/386 product, 658

766

Index

C C C

 

CCC

 

C

C

C

outp() function, 288 output filename, 112

OutputDebugString() function, 655 outpw() function, 288

overflow, integer, 31 overlay programs, 670

overloading functions, 701-702

P

p and P fields, 611, 618 pack pragma, 636 packing

code segments, 670 data segments, 670 redundant bytes, 670

_page structure, 416 param parameter, 598, 601 parameters, 498

*argv[], 100

*envp[], 100 argc, 100

Array, 540, 544, 566 base, 527 BufferSize, 536 Category, 571

Character, 547-549, 550-551 chChar, 558, 578, 586, 597-598 Compare, 566

compare, 527 default values, 706

denominator, 531, 552

dIntegral, 562

dValue, 523-524, 528-533, 536, 541, 554, 562, 574-576, 594-595

dValue1, 525

ElementSize, 540, 544, 566 endtime, 531

filepointer, 529 function, 574 jumpbuffer, 555, 570 key, 527

Locale, 571 lOffset, 542 lValue, 552 Member, 563 Mode, 537 nBase, 591-592 nBufferSize, 581 nByte, 561 nChar, 565 nCharacter, 539 nConditional, 524

nCount, 528, 557, 584-585, 605 nError, 581

nException, 566 nExitCode, 532 nExponent, 541 nLength, 558-561, 593 nMode, 572 nNewSize, 567 nOrigin, 542 nReturnCode, 555 nSeed, 576

nSignal, 574 nSize, 528, 572 num, 527

NumberElements, 540, 544, 566 numerator, 531, 552

767