The GNU Pascal Manual
Total Page:16
File Type:pdf, Size:1020Kb
The GNU Pascal Manual Jan-Jaap van der Heijden, Peter Gerwinski, Frank Heckenbach, Berend de Boer, Dominik Freche, Eike Lange, Peter N Lewis, and others Last updated Jan 2005 for version 20050331 (GCC 2.8.1, 2.95.x, 3.2.x, 3.3.x or 3.4.x) Copyright c 1988-2005 Free Software Foundation, Inc. For GPC 20050331 (GCC 2.8.1, 2.95.x, 3.2.x, 3.3.x or 3.4.x) Published by the Free Software Foundation 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA Permission is granted to make and distribute verbatim copies of this manual provided the copy- right notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the con- ditions for verbatim copying, provided also that the sections entitled “GNU General Public License”, “The GNU Project”, “The GNU Manifesto” and “Funding for Free Software” are included exactly as in the original, and provided that the entire resulting derived work is dis- tributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that the sections entitled “GNU General Public License”, “The GNU Project”, “The GNU Manifesto” and “Funding for Free Software” and this permission notice, may be included in translations approved by the Free Software Foundation instead of in the original English. i Short Contents GNU Pascal ......................................... 1 Welcome to GNU Pascal . ............................. 3 1 Some of GPC’s most interesting features. .................. 5 2 New Features of GNU Pascal. ......................... 9 3 The GNU Pascal Frequently Asked Questions List. .......... 15 4 How to download, compile and install GNU Pascal. .......... 27 5 Command Line Options supported by GNU Pascal. .......... 35 6 The Programmer’s Guide to GPC ...................... 47 7 A QuickStart Guide from Borland Pascal to GNU Pascal. ..... 237 8 The Alphabetical GPC Language Reference .............. 257 9 Pascal keywords and operators supported by GNU Pascal. .... 453 10 Where to get support for GNU Pascal; how to report bugs. .... 459 11 The GNU Pascal To-Do List. ........................ 465 12 The GPC Source Reference.......................... 475 Appendix A GNU GENERAL PUBLIC LICENSE ............ 491 Appendix B GNU LESSER GENERAL PUBLIC LICENSE ..... 497 Appendix C DEMO COPYING ......................... 505 Appendix D Contributors to GNU Pascal. .................. 507 Appendix E Resources For Use With GPC. ................. 513 Appendix F The GNU Project. ......................... 517 Index-GPC ........................................ 527 ii The GNU Pascal Manual iii Table of Contents GNU Pascal ..................................... 1 Welcome to GNU Pascal . ..................... 3 1 Some of GPC’s most interesting features. ...... 5 2 New Features of GNU Pascal. ................. 9 3 The GNU Pascal Frequently Asked Questions List. ....................................... 15 3.1 GNU Pascal ............................................... 15 3.1.1 What and why? ................................... 15 3.1.2 What is the current version? ........................ 15 3.1.3 Is it compatible with Turbo Pascal (R)? ............. 16 3.1.4 Which platforms are supported by GNU Pascal? ..... 16 3.2 Installing GPC ............................................. 16 3.2.1 What to read next ................................. 17 3.2.2 Which components do I need to compile Pascal code? .................................................... 17 3.2.3 How do I debug my Pascal programs? ............... 17 3.2.4 What additional libraries should I have? ............. 18 3.2.5 Contributed units .................................. 19 3.2.6 Can you recommend an IDE? ....................... 19 3.3 GNU Pascal on the DJGPP (MS-DOS) platform .............. 19 3.3.1 What is DJGPP? .................................. 19 3.3.2 If you need more information ....................... 19 3.3.3 What do I download? .............................. 20 3.3.4 How do I install the compiler? ...................... 20 3.3.5 I cannot read the Info documentation! ............... 21 3.3.6 GPC says: no DPMI ............................... 21 3.3.7 I have troubles with assembly code .................. 21 3.3.8 Tell me how to do DPMI, BIOS and other DOS related things. .............................................. 21 3.3.9 I got an exception when accessing an ‘array [1 .. 4000000] of Byte’. .................................. 23 3.4 Strings .................................................... 23 3.4.1 What’s this confusion about strings? ................ 23 3.4.2 Overlaying strings in variant records ................ 24 3.4.3 Why does ‘s[0]’ not contain the length? ............ 24 3.4.4 Watch out when using strings as parameters ......... 24 3.4.5 Support for BP compatible short strings ............. 25 3.4.6 What about C strings? ............................. 25 3.5 Getting Help ............................................... 25 3.6 Miscellaneous .............................................. 26 3.6.1 I want to contribute; where do I start? .............. 26 3.6.2 Where is the GNU Pascal web site? ................. 26 3.6.3 About this FAQ ................................... 26 iv The GNU Pascal Manual 4 How to download, compile and install GNU Pascal. ..................................... 27 4.1 Where and what to download ............................... 27 4.2 Installation instructions for a GPC binary distribution ........ 29 4.3 Compiling GPC ............................................ 30 4.4 Compilation notes for specific platforms ...................... 33 4.4.1 MS-DOS with DJGPP ............................. 33 4.4.2 MS-DOS or OS/2 with EMX ....................... 33 4.4.3 MS Windows 95/98/NT ............................ 33 4.5 Building and Installing a cross-compiler ...................... 33 4.6 Crossbuilding a compiler .................................... 34 5 Command Line Options supported by GNU Pascal. ..................................... 35 5.1 GPC options besides those of GCC........................... 35 5.2 The most commonly used options to GPC .................... 44 6 The Programmer’s Guide to GPC ............ 47 6.1 Source Structures .......................................... 47 6.1.1 The Source Structure of Programs .................. 47 6.1.2 Label Declaration .................................. 48 6.1.3 Constant Declaration .............................. 48 6.1.4 Type Declaration .................................. 50 6.1.5 Variable Declaration ............................... 51 6.1.6 Subroutine Declaration ............................. 52 6.1.6.1 The Procedure ............................ 52 6.1.6.2 The Function ............................. 53 6.1.6.3 The Operator ............................. 53 6.1.6.4 Subroutine Parameter List Declaration...... 53 6.1.7 Statements ........................................ 56 6.1.7.1 Assignment ............................... 56 6.1.7.2 begin end Compound Statement............ 56 6.1.7.3 if Statement .............................. 56 6.1.7.4 case Statement ............................ 56 6.1.7.5 for Statement ............................. 57 6.1.7.6 while Statement........................... 58 6.1.7.7 repeat Statement.......................... 59 6.1.7.8 asm Inline ................................ 59 6.1.7.9 with Statement ........................... 59 6.1.7.10 goto Statement .......................... 59 6.1.7.11 Procedure Call ........................... 59 6.1.7.12 The Declaring Statement ................. 59 6.1.7.13 Loop Control Statements ................. 60 6.1.8 Import Part and Module/Unit Concept.............. 60 6.1.8.1 The Source Structure of ISO 10206 Extended Pascal Modules ............................... 60 6.1.8.2 The Source Structure of UCSD/Borland Pascal Units......................................... 63 6.2 Data Types ................................................ 64 6.2.1 Type Definition.................................... 64 6.2.2 Ordinal Types ..................................... 64 6.2.3 Integer Types ..................................... 64 6.2.3.1 The CPU’s Natural Integer Types .......... 65 6.2.3.2 The Main Branch of Integer Types ......... 65 v 6.2.3.3 Integer Types with Specified Size ........... 65 6.2.3.4 Integer Types and Compatibility ........... 66 6.2.3.5 Summary of Integer Types ................. 66 6.2.4 Built-in Real (Floating Point) Types ................ 68 6.2.5 Strings Types ..................................... 68 6.2.6 Character Types ................................... 68 6.2.7 Enumerated Types................................. 68 6.2.8 File Types ........................................ 69 6.2.9 Boolean (Intrinsic) ................................. 69 6.2.10 Pointer (Intrinsic) ................................ 69 6.2.11 Type Definition Possibilities ....................... 70 6.2.11.1 Subrange Types .......................... 70 6.2.11.2 Array Types ............................. 70 6.2.11.3 Record Types ............................ 71 6.2.11.4 Variant Records.......................... 72 6.2.11.5 EP’s Schema Types including ‘String’..... 72 6.2.11.6 Set Types ............................... 76 6.2.11.7 Pointer Types............................ 76 6.2.11.8 Procedural and Functional Types.......... 77 6.2.11.9 Object Types ............................ 78 6.2.11.10 Initial values to type denoters ............ 79 6.2.11.11 Restricted