HP SunSoft Pascal 4.0 User Manual

Pascal 4.0 User’s Guide
A Sun Microsystems, Inc. Business
2550 Garcia Avenue Mountain View, CA 94043 U.S.A.
Part No.: 802-2943-10 Revision A, November 1995
1995 Sun Microsystems, Inc. 2550 Garcia Avenue, Mountain View, California 94043-1 100 U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses r estricting its use,
copying, distribution and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any .
Portions of this product may be derived from the UNIX
®
system and from the Berkeley 4.3 BSD system, licensed from the University of California. Third-party software, including font technology in this product, is pr otected by copyright and licensed from Sun’s Suppliers. RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government is subject to restrictions as set forth in
subparagraph (c)(1)(ii) of the Rights in T echnical Data and Computer Software clause at DFARS 252.227-7013 and F AR 52.227-19.
The product described in this manual may be protected by one or more U.S. patents, foreign patents, or pending applications. TRADEMARKS
Sun, the Sun logo, Sun Microsystems, Sun Microsystems Computer Corporation, Solaris, the Sun Microsystems Computer Corporation logo, SunSoft, the SunSoft logo, ProW orks, ProWorks/T eamWare, ProCompiler, Sun-4, SunOS, ONC, ONC+, NFS, OpenWindows, DeskSet, ToolT alk, SunV iew, XV iew , X1 1/NeWS, AnswerBook, and Magnify Help are trademarks or register ed trademarks of Sun Microsystems, Inc. in the United States and may be protected as trademarks in other countries. UNIX is a registered trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd. OPEN LOOK is a registered trademark of Novell, Inc. PostScript and Display PostScript are trademarks of Adobe Systems, Inc. PowerPC™ is a trademark of International Business Machines Corporation. HP
®
and HP-UX® are registered trademarks of
Hewlett-Packard Company . All other pr oduct names mentioned herein are the trademarks of their r espective owners. All SP ARC trademarks, including the SCD Compliant Logo, are trademarks or register ed trademarks of SP ARC International,
Inc. in the United States and may be protected as trademarks in other countries. SP ARCcenter , SPARCcluster , SP ARCompiler, SP ARCdesign, SP ARC81 1, SPARCengine, SP ARCprinter , SPARCserver , SPARCstation, SP ARCstorage, SPARCworks, microSP ARC, microSPARC-II, SP ARCware, and UltraSPARC are licensed exclusively to Sun Microsystems, Inc. Pr oducts bearing SP ARC trademarks are based upon an architectur e developed by Sun Microsystems, Inc.
Please
The OPEN LOOK™ and Sun™ Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry . Sun holds a non-exclusive license from Xer ox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUI’s and otherwise comply with Sun’s written license agreements.
X Window System is a product of X Consortium, Inc. THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.
Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Pascal Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Text Editors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Debuggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
XView Toolkit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Native Language Support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Internationalization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Licensing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2. Pascal Programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
A Simple Pascal Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
iii
Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Renaming the Executable File . . . . . . . . . . . . . . . . . . . . . . . . 9
An Interactive Pascal Program. . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Redirecting I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Using a File Name as a File Variable . . . . . . . . . . . . . . . . . . . 12
Where Did My Program Fail?. . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using Pascal Traceback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using a Sample Program with Segmentation Violation . . . 14
3. The Pascal Compiler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
pc Version Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Compile and Link Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Language Preprocessor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
File Name Extensions Accepted By pc . . . . . . . . . . . . . . . . . . . . 20
Option-Passing on the Command-Line. . . . . . . . . . . . . . . . . . . . 21
Option-Passing in the Program Text . . . . . . . . . . . . . . . . . . . . . . 21
Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
–a. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
–Bbinding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
–b. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
-bsdmalloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
–C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
iv Pascal 4.0 User’s Guide
–c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
-calign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
–cg89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
–cg92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
-cond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
–config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
–Dname[=def]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
–dalign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
-dn. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
-dryrun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
-dy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
–fast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
-fnonstd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
–fns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
–fround=r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
–ftrap=t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
-G. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
–g. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
–H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
-hname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
–help or -flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
–Ipathname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
–i name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
-keeptmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Contents v
–L. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
–l. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
-Ldirectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
-libmieee. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
–libmil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
–llib. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
–misalign. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
-mt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
–native . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
-nocx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
-nolib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
–nolibmil. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
-noqueue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
-notrace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
–O[level]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
–o filename. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
–P. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
–p and –pg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
–pic, -Kpic and –PIC, -KPIC. . . . . . . . . . . . . . . . . . . . . . . 39
–Qoption. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
–Qpath pathname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
–Qproduce. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
-qp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
-R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
vi Pascal 4.0 User’s Guide
-R path[:dir] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
-Rw. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
–S. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
–s[level]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
–sb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
–sbfast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
-tc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
–temp=dir. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
–time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
–U name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
–V. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
–V0 and –V1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
–v. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
–w. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
-xa. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
-xarch=a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
-xcache=c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
-xchip=c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
-xcg89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
-xcg92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
–xF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
-xildoff. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
-xildon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
–xl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Contents vii
-xlibmieee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
-xlibmil. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
-xlibmopt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
–xlicinfo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
–xMerge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
-xnolib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
-xnolibmopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
-x05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
-xpg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
-xprofile=p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
-xregs=r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
–xs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
-xsafe=mem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
-xsb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
-xsbfast. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
-xspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
-xtarget=t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
–Z. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
-ztext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4. Program Construction and Management . . . . . . . . . . . . . . . . . 67
Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Using Program Units and Module Units . . . . . . . . . . . . . . . 68
Compiling with Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Using Units and Header Files . . . . . . . . . . . . . . . . . . . . . . . . 70
viii Pascal 4.0 User’s Guide
Sharing Variables Between Units. . . . . . . . . . . . . . . . . . . . . . 71
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5. Separate Compilation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Working with Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Using Program Units. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Using Module Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Sharing Variables and Routines Across Multiple Units . . . . . . 76
Compiling without the -xl Option . . . . . . . . . . . . . . . . . . . . 77
Using the -xl Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Sharing Declarations in Multiple Units. . . . . . . . . . . . . . . . . . . . 87
6. The C–Pascal Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Compilation of Mixed-Language Programs. . . . . . . . . . . . . . . . 89
Compatibility of Types for C and Pascal. . . . . . . . . . . . . . . . . . . 90
Precautions with Compatible Types . . . . . . . . . . . . . . . . . . . 91
Incompatibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
General Parameter Passing in C and Pascal . . . . . . . . . . . . . . . . 93
Procedure Calls: C–Pascal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Variable Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Value Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Input and Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Procedure Calls: Pascal–C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Variable Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Value Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Contents ix
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Parameters That Are Pointers to Procedures . . . . . . . . . . . . 131
Procedures and Functions as Parameters . . . . . . . . . . . . . . . . . . 132
Global Variables in C and Pascal . . . . . . . . . . . . . . . . . . . . . . . . . 133
File-Passing Between Pascal and C . . . . . . . . . . . . . . . . . . . . . . . 134
7. The C++–Pascal Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Sample Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Compatibility of Types for C++ and Pascal . . . . . . . . . . . . . . . . 138
C++ Name Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Procedure Calls: C++–Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Arguments Passed by Reference . . . . . . . . . . . . . . . . . . . . . . 139
Arguments Passed by Value. . . . . . . . . . . . . . . . . . . . . . . . . . 150
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Procedure Calls: Pascal–C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Arguments Passed by Reference . . . . . . . . . . . . . . . . . . . . . . 155
Arguments Passed by Value. . . . . . . . . . . . . . . . . . . . . . . . . . 157
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Global Variables in C++ and Pascal. . . . . . . . . . . . . . . . . . . . . . . 161
Pascal File Pointers to C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
8. The FORTRAN–Pascal Interface . . . . . . . . . . . . . . . . . . . . . . . . 163
Compiler Mixed-Language Programs. . . . . . . . . . . . . . . . . . . . . 163
Compatibility of Types for FORTRAN and Pascal. . . . . . . . . . . 164
Precautions with Compatible Types . . . . . . . . . . . . . . . . . . . 165
Incompatibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
x Pascal 4.0 User’s Guide
General Parameter-Passing in FORTRAN and Pascal. . . . . . . . 167
Procedure Calls: FORTRAN-Pascal . . . . . . . . . . . . . . . . . . . . . . . 168
Variable Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Value Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Procedure Calls: Pascal-FORTRAN . . . . . . . . . . . . . . . . . . . . . . . 185
Variable Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Value Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Routines as Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
9. Error Diagnostics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Compiler Syntax Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Illegal Characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
String Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Digits in Real Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Replacements, Insertions, and Deletions . . . . . . . . . . . . . . . 207
Undefined or Improper Identifiers . . . . . . . . . . . . . . . . . . . . 208
Expected Symbols and Malformed Constructs . . . . . . . . . . 208
Expected and Unexpected End-of-file. . . . . . . . . . . . . . . . . . 209
Compiler Semantic Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Format of the Error Diagnostics. . . . . . . . . . . . . . . . . . . . . . . 210
Incompatible Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Contents xi
The scalar Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Procedure and Function Type Errors. . . . . . . . . . . . . . . . . . . 211
Scalar Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Expression Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Type Equivalence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Unreachable Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
The goto Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Uninitialized Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Unused Variables, Constants, Types, Labels, and Routines 216
Compiler Panics, I/O Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Runtime Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
10. The XView Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Object-Oriented Programming. . . . . . . . . . . . . . . . . . . . . . . . 222
Pascal Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Compiling with Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Attribute Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Handles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Coding Fragment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Conversion of C to Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
xii Pascal 4.0 User’s Guide
An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Sample Translation of an XView Function to Pascal . . . . . . 229
Sample Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Menu Demo Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
11. Math Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Contents of the Math Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . 234
libm Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
IEEE Support Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
ieee_functions(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ieee_values() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ieee_retrospective() . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
SPARC Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Arithmetic Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Math Library Exception-Handling Function: matherr() . . . . 240
libsunmath Support for IEEE Modes and Exceptions . . . . . . 242
Contents xiii
xiv Pascal 4.0 User’s Guide
Figures
Figure 3-1 Organization of Pascal Compilation. . . . . . . . . . . . . . . . . . . . . . 19
Figure 3-2 Options in Program Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 10-1 A Sample Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
xv
xvi Pascal 4.0 User’s Guide
Tables
Table 3-1 File Name Suffixes Recognized by Pascal . . . . . . . . . . . . . . . . . 20
Table 3-2 Options That Can Be Passed in Program Text . . . . . . . . . . . . . 21
Table 3-3 The -xarch Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Table 3-4 The -xcache Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Table 3-5 The -xchip Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Table 3-6 The -xprofile Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Table 3-7 The -xregs Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Table 3-8 The -xtarget Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Table 3-9 -xtarget Expansions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Table 6-1 C and Pascal Size and Alignment of Compatible Types . . . . . 90
Table 6-2 C and Pascal Size and Alignment of Compatible Types with –xl
91
Table 6-3 Set Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Table 8-1 Default Sizes and Alignments of Compatible Types (Pascal and
FORTRAN). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
–xl
with –xl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
xvii
Table 10-1 C Declarations to Pascal Declarations . . . . . . . . . . . . . . . . . . . . 228
Table 11-1 Contents of Math Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
xviii Pascal 4.0 User’s Guide
Operating Environment
Installation
Preface
This manual describes the Pascal 4.0 compiler from SunSoft™. The purpose of this manual is to help you begin writing and compiling Pascal programs on a SPARCstation™.
In a previous major release, this Pascal compiler also ran on Solaris 1.x. Some features remain in the documentation as being for Solaris 1.x only.
The README file that accompanies the product contains other release-specific information,
Note – All references to Pascal in this manual refer to the Pascal 4.0 compiler unless otherwise indicated.
For information on the operating environment, see the README file.
For instructions on how to install Pascal, refer to the Installing SunSoft Developer Products (SPARC/Solaris) manual.
xix
Audience
Organization
This guide was prepared for software engineers who write Pascal programs on a SPARCstation. It assumes you are familiar with ISO standard Pascal and the Solaris™ operating system.
This guide contains the following chapters:
Chapter 1, “Introduction,” gives basic information about the Pascal
compiler and related program development tools.
Chapter 2, “Pascal Programs,” describes how to write, compile, and run a
Pascal program.
Chapter 3, “The Pascal Compiler,” describes the pc command and its
options.
Chapter 4, “Program Construction and Management,” is an introduction to
how complex programs are built in Pascal.
Chapter 5, “Separate Compilation,” describes how programs can be
divided into several units, and how they are compiled and linked.
Chapter 6, “The C–Pascal Interface,” describes how to write programs that
are partly in C and partly in Pascal.
Chapter 7, “The C++–Pascal Interface,” describes how to write programs
that are partly in C++ and partly in Pascal.
Chapter 8, “The FORTRAN–Pascal Interface,” describes how to write
programs that are partly in FORTRAN and partly in Pascal.
Chapter 9, “Error Diagnostics,” describes the errors you may encounter
while writing programs with Pascal.
Chapter 10, “The XView Toolkit,” describes how to use the XView toolkit
with Pascal.
Chapter 11, “Math Libraries,” describes how to use the libm and
libsunmath functions in Pascal programs.
Appendix A, “Pascal Preprocessor,” describes the Pascal preprocessors,
with emphasis on the nonstandard preprocessor, cppas.
xx Pascal 4.0 User’s Guide
Appendix B, “Error Messages,” lists all the error messages the compiler
produces.
This guide concludes with an index.
Conventions Used in This Guide
This guide contains syntax diagrams of the Pascal language in extended Backus-Naur Formalism (BNF) notation. Here are the meta symbols:
Table P-1 BNF Meta Symbols
Meta Symbol Description
::= Defined as | Can be used as an alternative (a | b) Either a or b [ a ] Zero or one instance of { a } Zero or more instances of a 'abc' The characters abc
The following table describes the type styles and symbols used in this guide:
Table P-2 Typographic Conventions
a
Typeface or Symbol Meaning Example
AaBbCc123 The names of commands, files, and
directories; on-screen computer output
AaBbCc123 What you type, contrasted with on-
screen computer output
AaBbCc123 Command-line placeholder:
replace with a real name or value
AaBbCc123 Book titles, new words or terms, or
words to be emphasized
Preface xxi
Edit your .login file. Use ls -a to list all files.
hostname% You have mail.
hostname% su Password:
To delete a file, type rm filename.
Read the User’s Guide. These are called class options. You must be root to do this.
Shell Prompts in Command Examples
The following table shows the default system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell.
Table P-3 Shell Prompts
Shell Prompt
C shell prompt machine_name% C shell superuser prompt machine_name# Bourne shell and Korn shell prompt $ Bourne shell and Korn shell superuser prompt #
Related Documentation
This manual is designed to accompany the following documents:
The Pascal 4.0 Reference Manual, which describes extensions to standard
Pascal
The Pascal 4.0 Quick Reference, which summarizes the compiler options
Both this manual and the Pascal 4.0 Reference Manual are available in the AnswerBook® system, an on-line documentation viewing tool that takes advantage of dynamically linked headings and cross-references. The Installing SunSoft Developer Products (SPARC/Solaris) manual shows you how to install AnswerBook.
Manual Page
Pascal 4.0 provides an on-line manual page (also known as man page), on pc(1), that describes the Pascal compiler. This document is included in the Pascal package and must be installed with the rest of the software
Once you install the documentation, you can read about pc by entering the
man command followed by the command name, as in:
hostname% man pc
xxii Pascal 4.0 User’s Guide
README Files
The README default directory is: /opt/SUNWspro/READMEs. This directory contains the following files:
A Pascal 4.0 README, called pascal, that describes the new features,
software incompatibilities, and software bugs
A floating-point white paper, “What Every Scientist Should Know About
Floating-Point Arithmetic,” by David Goldberg, in PostScript™ format. The
file is called floating-point.ps, and can be printed on any PostScript­compatible printer that has Palatino font. It can be viewed on-line by using the imagetool command:
hostname% imagetool floating-point.ps
This paper is also available in the AnswerBook system.
Other Related Documentation
Other reference material includes:
Profiling Tools Numerical Computation Guide
Documents in Hard Copy and in AnswerBook
The following table shows what documents are on-line, in hard copy, or both:
Table P-4 Documents in Hard Copy and in AnswerBook
Title Hard Copy On-Line
Pascal 4.0 User’s Guide X X (AnswerBook) Pascal 4.0 Reference Manual X X (AnswerBook) Pascal 4.0 Quick Reference X Installing SunSoft Developer Products (SPARC/Solaris) X X (AnswerBook) Profiling Tools X (AnswerBook)
Preface xxiii
Table P-4 Documents in Hard Copy and in AnswerBook (Continued)
Title Hard Copy On-Line
Numerical Computation Guide X (AnswerBook)
README X (CD-ROM)
What Every Scientist Should Know About Floating-Point Arithmetic X (AnswerBook and CD-ROM)
xxiv Pascal 4.0 User’s Guide
Standards
Introduction
This chapter gives an overview of the features of Pascal, including compatibility, internationalization, and licensing. It contains the following sections:
Standards page 1 Pascal Compiler page 2 Features page 2 Compatibility page 2 Text Editors page 3 Debuggers page 3 XView Toolkit page 3 Native Language Support page 3 Licensing page 5
Pascal is a derivative of the Berkeley Pascal system distributed with UNIX® 4.2 BSD. It complies with FIPS PUB 109 ANSI/IEEE 770 X3.97-1983 and
BS6192/ISO7185 at both level 0 and level 1.
1
1
1
Pascal Compiler
Features
The name of the Pascal compiler is pc. If given an argument file name ending with .p or .pas, pc compiles the file and leaves the result in an executable file, called a.out by default.
Pascal includes many extensions to the standard, including the following:
Separate compilation of programs and modules
dbx (symbolic debugger) support
Optimizer support
Multiple label, const, type, and var declarations
Variable-length character strings
Compile-time initializations
static and extern declarations
Different sizes of integer and real data types
Integer constants in any base, from 2 to 16
Extended input/output facilities
Extended library of built-in functions and procedures
Universal and function and procedure pointer types
Direction of parameter passing: into a routine, out of a routine, or both
Functions that return structured-type results
Note – For other release-specific information, please refer to the README file that accompanies the product release.
Compatibility
In general, Pascal 4.0 runs in the Solaris 2.x or above operating environment. This product is not compatible with /usr/ucblib/libucb.a on the Solaris
2.x environment.
2 Pascal 4.0 User’s Guide
Text Editors
Debuggers
1
The operating system provides two main editors:
Text Editor—A window-based text editor that runs in the OpenWindows
environment. Start this tool by typing textedit at the system prompt.
vi—The standard visual display editor that offers the capabilities of both a
line and a screen editor. It also provides several commands for editing programs. For example:
The autoindent option provides white space at the beginning of a line.
The showmatch option shows matching parentheses.
SunSoft offers a variety of programming tools that run in the Solaris operating environment. For debugging, the following tools are available:
dbx—A symbolic debugger
debugger—A window- and mouse-based version of the symbolic debugger
You can use Pascal with fix-and-continue, a debugger functionality. See the debugger documentation for details of this feature.
XV iew Toolkit
The XView application programmer ’s interface (API) is an object-oriented and server-based user-interface toolkit for the X Window System Version 11 (X11). It is designed for manipulating XView windows and other XView objects. Chapter 10, “The XView Toolkit,” describes how to use XView with Pascal.
Native Language Support
Sun supports the development of applications in languages other than English. These languages include most European languages and Japanese. As a result, you can easily switch your application from one native language to another. This feature is known as internationalization.
Introduction 3
1
Internationalization
A product can support up to four levels of internationalization:
Level 1—Allows native-language characters (such as the a-umlaut). This is
referred to as the 8-bit clean model because the eighth bit in each byte is used to represent native-language characters.
Level 2—Recognizes and displays international date and time formats, such
as 26.07.90 in Italian; international decimal units, such as 1.234.567,89 in French; and international monetary units, such as 1.234,56 Pts in Spanish.
Level 3—Contains support for localized messages and text presentation.
Level 4—Contains Asian language support.
Pascal supports all four levels. See the Pascal 4.0 Reference Manual for a description of the date and time functions in internationalized formats.
Pascal does not allow input and output in the various international formats. If it does, it does not comply with the Pascal language standard, ANSI/IEEE 770 X3.97-1983.
For example, the standard specifies a period (.) as the decimal unit in the floating-point representation. Consider the following program, which prints a floating-point value:
program sample(output);
var r : real := 1.2;
begin
writeln(r);
end.
When you compile and run the program on the internationalized Pascal compiler, the output is:
1.20000000000000e+00
4 Pascal 4.0 User’s Guide
Licensing
1
If you reset your system locale to, for example, France, and rerun the program, the output is the same. Pascal does not replace the period with a comma, the French decimal unit.
Locale
You can change your application from one native language to another by setting the locale. For information on this and other native language support features, see the Solaris documentation on internationalization.
This compiler uses network licensing, as described in the manual, Installing SunSoft Developer Products (SPARC/Solaris).
When you invoke the compiler, if a license is available, the compiler starts. If no license is available, your request for a license is put on a queue, and your compile job continues when a license becomes available. A single license can be used for any number of simultaneous compiles by a single user on a single machine. There are two licensing-related options:
-noqueue—Does not queue request if no license is available.
-xlicinfo—Returns information on the status of licensing.
The -xlicinfo option does not check out a license. For details on how to obtain a license—where to call, what information to have
ready—refer to the manual, Installing SunSoft Developer Products
(SPARC/Solaris).
Introduction 5
1
6 Pascal 4.0 User’s Guide
Loading...
+ 303 hidden pages