BORLAND
Turbo Pascal®
Reference Guide
Version 5.0
Copyrightc 1983,1989 All rights reserved Borland International 1800 Green Hills Road P.O. Box 660001 Scotts Valley, CA 9~1
R3
This manual was produced
withSprintOP The Professional Word Processor
All Borland products are trademarks or registered trademarks of Borland International, Inc. Other brand and product names are trademarks
or registered trademarks of their respective holders.
Copyrighto 1989 Borland International.
Printed in the U.S.A.
109876543
Table of Contents
Introduction 1
What's On Your Disks 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Installing Turbo Pascal On Your System 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 About This Manual 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • 0 • 0 0 4 Typography 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 How to Contact Borland 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 5 Part 1 Programmer's Reference
Chapter 1 Tokens and Constants 9
Special Symbols and Reserved Words 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 Iden tifiers 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • 0 0 0 0 11
!.abels 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • • • • • • • 0 0 0 0 0 0 0 0 0 0 12 Numbers 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 Character Strings 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 Constant Declarations 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 15 Comments 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 Program Lines 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 Chapter 2 Blocks, Locality, and Scope 17 Syntax 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . 0 17 Rules of Scope 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 Scope of Interface and Standard Identifiers 0 0 0 0 0 0 0 • • • 0 • 0 • • • • 0 0 0 0 0 0 0 0 19
Chapter 3 Types 21
Simple Types 0 0 0 0 0 0 • 0 • • 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 • 0 0 0 • 0 • 0 • 0 0 0 0 0 0 0 . 0 0 • • 0 22 Ordinal Types . 0 0 0 0 0 • • • 0 • 0 • 0 0 0 0 0 • 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 • 0 • • 22 Integer Types o. 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • • • 0 0 0 0 0 0 0 • • 0 23 Boolean Type 0 0 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 • • 0 0 0 • 0 0 0 0 0 0 0 0 o . 24 Char Type 0 0 0 • 0 0 0 • 0 0 0 0 0 0 • • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 24 Enumerated Types 0 0 0 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 • • • 0 0 0 0 0 . 0 • • • • • 0 0 . 0 0 0 0 • • 24 Subrange Types 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • 0 0 0 0 0 0 0 0 0 • 0 • • 0 0 0 0 0 0 0 0 • • 25 Real Types 0 0 0 0 0 0 0 0 0 0 • 0 • 0 • • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 • • 0 0 0 0 0 0 0 0 • 0 0 0 • 0 26 Software Floating Point 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 • • 0 0 0 0 0 26 8087 Floating Point 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 • 0 0 • • 0 27 String Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • • 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 27 Structured. Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 Array Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 Record Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 29 Set Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 31 File Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 31
Pointer Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 Procedural Types 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 Identical and Compatible Types 0 . 0 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • 0 0 0 0 0 0 33 Type Identity 0 " 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 • 0 0 • 0 • 0 0 0 • 0 0 33 Type Compatibility 0 0 • 0 0 0 0 • 0 0 • 0 0 • 0 • 0 0 0 0 0 • • 0 0 0 0 • 0 0 0 • • 0 0 0 0 0 0 0 0 0 • • 34 Assignment Compatibility ... 0 . . 0 0 0 0 0 . . 0 . . 0 • • • • 0 . . . 0 0 • • 0 • • 0 34 The Type Declaration Part .. 0 0 • 0 0 0 0 • 0 • 0 0 0 0 0 • 0 0 • 0 0 0 0 0 0 • 0 • 0 0 0 0 • • • 0 • 0 35
Chapter 4 Variables 37
Variable Declarations 0 0 0 0 • • 0 0 0 • • 0 0 0 0 0 0 . 0 0 0 • • • • 0 0 0 • • 0 0 0 0 0 0 0 0 0 0 0 • • 0 37 The Data Segment 0 0 0 0 0 0 0 0 0 • 0 • 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 • 0 0 0 0 0 0 0 0 • 0 0 38 The Stack Segment 0 0 0 • • • 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 0 • 0 • 0 0 • 0 0 0 • 0 0 0 0 • 0 0 0 0 0 • • 38 Absolute Variables 0 0 0 0 0 • • • • 0 . 0 0 . 0 0 0 0 0 0 0 0 0 . 0 . 0 0 0 0 0 0 . 0 0 0 0 0 0 . 0 0 0 0 39 Variable References .. 0 • 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • • 0 0 0 0 0 0 0 0 0 0 0 • • 0 0 39 Qu.alifiers 0 0 0 0 0 0 0 0 0 • 0 0 • 0 • 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 • • • 0 0 0 0 • 0 0 0 • 0 40 Arrays, Strings, and Indexes ... 0 0 0 0 • 0 0 0 0 0 • • 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 0 • 0 • • 0 41 Records and Field Designators. 0 " 0 0 " 0 . 0 0 . 0 . . 0 0 0 0 . . . 0 . . . . 0 0 0 • • 0 41 Pointers and Dynamic Variables . 0 0 0 0 0 0 0 0 0 0 • 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 42 Variable Typecasts 0 0 0 0 0 0 0 . 0 0 0 • • 0 0 . 0 . 0 0 0 0 0 0 . 0 0 . 0 ' . 0 • • • 0 0 0 0 0 0 0 • • 0 • • 42
Chapter 5 Typed Constants 45
Simple-Type Constants 0 • • 0 • 0 0 0 0 0 • 0 • 0 0 0 0 • 0 0 0 • 0 • 0 0 0 0 0 0 0 • 0 0 0 0 0 • 0 • 0 0 46 String-Type Constants 0 0 • • • 0 . 0 0 • • • 0 • 0 0 0 0 • • • • 0 • 0 0 . 0 0 0 0 0 0 0 0 0 0 0 . 0 • • • 46 Structured-Type Constants o. 0 • • • • • • 0 . 0 . 0 0 0 0 0 0 0 0 0 0 . 0 0 0 0 0 . 0 0 0 0 0 0 . 0 0 46 Array-Type Constants 0 • • 0 0 0 0 0 • 0 0 0 0 0 0 • 0 0 0 0 0 0 • 0 • 0 0 0 0 0 • 0 0 0 0 0 0 • • • 0 47 Record-Type Constants .. 0 0 0 0 0 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . 0 0 0 . 0 0 • • 0 0 0 0 0 . 0 . 0 48 Set-Type Constants .. 0 0 • • 0 0 0 • • • 0 0 0 0 • 0 0 0 0 0 0 0 • 0 0 • • 0 0 0 • 0 • 0 0 0 • 0 • 0 0 "0 48 Pointer-Type Constants 0 0 0 • • 0 0 • • 0 0 • 0 • 0 0 0 0 0 0 • • 0 0 0 0 0 0 0 • 0 0 0 0 0 0 • 0 0 • 0 0 49
Chapter 6 Expressions 51
Expression Syntax 0 • • • 0 0 • • • 0 0 0 0 0 • 0 • • 0 • 0 0 0 0 • • 0 0 0 0 0 • 0 0 • • 0 • 0 0 0 0 • 0 • • • 52 Operators .. 0 0 0 0 0 0 0 • • • 0 0 • • • 0 • • • 0 0 • 0 • 0 • 0 0 • • • 0 • • 0 0 0 • 0 0 0 • • 0 0 0 0 0 • • o . 54 Arithmetic Operators 0 0 0 0 0 0 0 0 • • • 0 0 0 0 • 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 . 0 0 54 Logical Opera tors ... 0 • • • • • • • • • • • • • • • • • • • • • • • • • • 0 0 • • • • • • • 56 B<>olean Operators 0 • • 0 • • 0 0 0 0 0 0 0 . 0 0 0 . 0 • • 0 • 0 0 0 0 0 • • 0 . 0 0 0 . 0 0 . 0 0 0 0 . 0 56 String Operator . 0 • • • 0 • • 0 0 0 0 0 0 0 0 0 0 0 • 0 0 0 0 0 • 0 0 0 0 0 • 0 0 • • 0 • 0 0 0 0 • 0 • 0 0 57 Set Operators 0 0 0 0 0 • 0 • 0 0 • 0 0 0 0 0 0 0 0 0 • • 0 • 0 0 0 0 • • • • 0 0 0 0 0 0 • • 0 0 • 0 0 0 • • • 58 Relational Operators 0 0 0 • • 0 0 0 0 0 0 0 0 0 0 0 . 0 0 0 0 0 • • 0 0 0 0 0 0 0 0 0 • 0 0 0 . 0 0 • • • 58 Comparing Simple Types 0 0 0 0 0 • • 0 0 • 0 0 • • 0 0 • 0 0 0 0 0 • • 0 0 • • 0 0 0 0 0 0 • • • 59 Comparing Strings 0 0 • • 0 0 0 0 0 0 • 0 0 0 • 0 • 0 • • • • • • 0 0 • 0 0 0 • • • 0 0 0 • • • • • • 59 Comparing Packed Strings . 0 • • 0 0 0 • 0 • • 0 0 • • 0 • 0 0 • 0 0 0 • • • • 0 0 0 • 0 0 • • 60 Comparing Pointers ... 0 • • • 0 0 • • • 0 • • • • • • 0 0 0 • 0 • 0 0 • • 0 0 0 • • 0 0 • 0 60 Comparing Sets ... 0 • • • • • • 0 • • • • • • 0 • 0 • • • 0 0 • 0 0 0 • • 0 0 0 0 • • 0 0 • 0 0 0 0 0 60 Testing Set Membership .. 0 0 0 0 • • 0 • • 0 0 • • 0 0 • 0 0 0 0 0 • • • 0 0 • 0 0 • 0 0 • 0 0 0 60 The @ Operator 0 0 0 • • • • • • • 0 0 0 • • • • • • • • • 0 0 0 0 • • • • 0 0 0 0 • • • • • 0 0 • • • • • 0 61
@ with a Variable .. 0 0 0 0 0 0 • 0 • 0 0 • • • • 0 0 0 0 0 • • • 0 0 0 0 • • 0 . 0 • 0 0 0 • 0 • • • • 61
@ with a Value Parameter ... 61
@ with a Variable Parameter ... 0 • • • • • • • • • • • • • • • • • • • • • • • • • • 62 @ with a Procedure or Function .... 0 • • • • • • • • • • • • • • • • • • • 0 • • • • • • 62 Function Calls ... 0 • • • • • • • • • • • • • • • • • • • • • 0 • • • • 62 Set Constructors ... 0 • • • • • • • • • • • • • • • • • • • 0 • • 0 0 • • 63 Value Typecasts ... 0 • • • • • • • • • • • 0 • • • • • • • • • • • • • • • • • • • 0 • 0 • • • • 64 Chapter 7 Statements 65 Simple Statements ... 0 • • • • • • • 0 • • • • 0 • • 0 • • • 0 • • • 0 • • • • • • • 0 • • 0 • • • • 65 Assignment Statements ... 0 • • • • • • • • • • • • • • • • • • • • • 0 • • • • 66 Proced.ure Statements ... 0 • • • • 66 Goto Statements ... 0 • • • • 67 Structured Statements ... 0 • • • • • • • • • • • • • • • • • • • • • • • • • • 67 Compound Statements ... 0 • • • • • • • • • • • • • • • • • 0 • • • • • • • • • • 0 • • • • 67 Conditional Statements ... 0 • • • • • • • • • • • • • • • • • • • • • 0 • • • • 68 If Statements ... 0 • • • • 68 Case Statements ... 0 • • • • • • • • • • • • • • 0 • • • • 69 Repetitive Statements ... 0 • • • • • • • • • • • 0 • • • • 70 Repeat Statements ... 0 • • • • 70 While Statements ... 0 • • • 0 ~ • • • • • • • • • 0 • • • • 71 For Statements ... 0 • • • • 72 With Statements ... 74
Chapter 8 Procedures and Functions 77 Procedure Declarations ... ' .. 0 • • • • • • • • 77 Forward Declarations ... 78
External Declarations ... 79
Inline Declarations ... 80
Function Declarations . . . .. 80
Parameters ... . Value Parameters ... . Variable Parameters ... . Untyped Variable Parameters ... . Procedural Types ... . Procedural Type Declarations ... 0 • • • • • • • • •
Procedural Variables ... o • • • • • • • • • • • • • • • • • • • • • • • • • • Procedural Type Parameters ... 0 • • • • • • • • • • • • • • • • • • •
Procedural Types in Expressions ... . Chapter 9 Programs and Units Program Syntax ... 0 0 • • • • • • • • • 0 • 0 • • • • • • • • • • • • • • • • • • • • • • • • • • • The Program Heading o. 0 • • • • • • • • • • • • • • • • • • • • • 0 • • • • • • • • • • • • • • • • The Uses Clause ... , ... 0 • • • • • • •
Unit Syntax ... . The Unit Heading ... 0 • • • • • • • • • • • • • 0 • • • • • • • • • • • • • • •
The Interface Part ... 0 • • • • • • • • • • • • • • • • 0 • • • • • • • • • • • • • • • •
82 82 83 83 84 84 85 87 89 93 93 93 93
94
95 95
The Implementation Part .. . . .. 95
The Initialization Part ... 96
Indirect Unit References . . . .. 96
Circular Unit References ... 97
Sharing Other Declarations ... 99
Chapter 10 Input and Output 101 An Introduction to I/O ... 101
Standard Procedures and Functions for All Files . . . .. 102
Procedures ... 102
Functions ... 103
Standard Procedures and Functions for Text Files ... 103
Procedures ... 104
Functions ... 104
Standard Procedures and Functions for Untyped Files. . . .. 105
The FileMode Variable. . . .. . .. . . .. . . .. . .. . .. . . ... 105
Devices in Turbo Pascal ... 106
OOS Devices ... 106
The CON Device ... 107
The LPT1, LPT2, and LPT3 Devices ... 107
The COM1 and COM2 Devices . . . .. 107
The NUL Device ... 107
Text File Devices ... 108
Chapter 11 Standard Procedures and Functions 109 Flow Control Procedures ... 109
Dynamic Allocation Procedures and Functions ... . . . .. 109
Procedures ... ' ... 110
Functions ... 110
Transfer Functions ... 110
Arithmetic Functions ... 110
Ordinal Procedures and Functions. . . .. 111
Procedures ... 111
Functions ... '. . . . .. 111
String Procedures and Functions ... 112
Procedures ... 112
Functions ... 112
Pointer and Address Functions. . . .. 112
Miscellaneous Procedures and Functions ... 112
Procedures ... 112
Functions ... 113
Chapter 12 Standard Units 115 Standard Unit Dependencies. . . .. 116
The System Unit ... 116
The Printer Unit ... 119