Pascal 4.0 User’s Guide
 Trademarks
 Contents
 Pascal Compiler
 Contents
 Pic, -Kpicand -PIC, -KPIC
 Contents Vii
 Program Construction and Management
Viii
 Separate Compilation
 C++-Pascal Interface
 Error Diagnostics
 XView Toolkit
Xii
 Contents Xiii
Math Libraries
 Xiv
 Figures
 Pascal 4.0 User’s Guide
 Tables
Fortran
 Xviii
 Operating Environment
Installation
Preface
 Audience
Organization
 Conventions Used in This Guide
AaBbCc123
 Manual
Shell Prompts in Command Examples
Related Documentation
 Readme Files
Other Related Documentation
Documents in Hard Copy and in AnswerBook
Hostname% imagetool floating-point.ps
 CD-ROM
 Introduction
Standards
 Compatibility
Features
Pascal Compiler
 Text Editors
Debuggers
XView Toolkit
Native Language Support
 Internationalization
 Licensing
Locale
 Pascal 4.0 User’s Guide
 Pascal Programs
Simple Pascal Program
 Compiling the Program
 Running the Program
Renaming the Executable File
Hostname% mv a.out temp
Hostname% pc -o temp temp.p
 An Interactive Pascal Program
 Redirecting I/O
Hostname% pc -o copy copy.p
Hello, are you listening?
Goodbye, I must go now
 Using a File Name as a File Variable
 Hostname% pc -o copy2 copy2.p
Where Did My Program Fail?
Using Pascal Traceback
 Using a Sample Program with Segmentation Violation
Compiling and Running the Program
 Using the -gOption
Hostname% more a.out.trace
 Try compiling SegViol.p with -g
 Pascal Compiler
Pc Version Number
 Compile and Link Sequence
Hostname% mcs -p a.out grep Pascal
 Language Preprocessor
Source
Compiler Preprocessor cpp or cppas
Optimizer
 File Name Extensions Accepted By pc
Suffix Description
 Option-Passing on the Command-Line
Option-Passing in the Program Text
Hostname% pc -l rmc.p
Hostname% pc -o rmc rmc.p
 Option Description
 Options
Hostname% pc options.p
 Bbinding
 Bsdmalloc
 Calign
Cg89
Cg92
Cond
 Config
Dname=def
 Fast
Dalign
Dryrun
 Fround=r
Fnonstd
Fns
 Ftrap=t
 Hname
 Help or -flags
Ipathname
Iname
Keeptmp
 Ldirectory
Hostname% pc -l random.p
 Libmieee
Libmil
Llib
Misalign
 Native
Nocx
Nolib
Nolibmil
 Notrace
Olevel
 Hostname% limit datasize 16M
 Ofilename
Hostname% /usr/sbin/swap -s
Hostname% /usr/sbin/prtconf grep Memory
Hostname% pc -o myprog myprog.p
 Using the -pOption
Using the -pgOption
-pg
Pic,-Kpic and -PIC,-KPIC
 Qproduce
Qoption
Qpathpathname
 Rpathdir
 Pascal 4.0 User’s Guide
 Examples
 Hostname% pc -Rw rr.p
Hostname% pc -Rw recvar.p
 Hostname% pc -Rw with.p
Commands to compile and execute with.p
Pascal main program, with.p with statement
 Hostname% pc -S rmc.p
Slevel
Sbfast
 Temp=dir
Hostname% pc -temp=. hello.p
 Time
Hostname% pc -time hello.p
 Uname
Xarch=a
 Pascal 4.0 User’s Guide
 Value Meaning
 Limit the instruction set to V8 architecture
 Xcache=c
S1/l1/a1 S1/l1/a1s2/l2/a2 S1/l1/a1s2/l2/a2s3/l3/a3
 Xchip=c
Example -xcache=16/32/41024/32/1specifies the following
 Xcg89
Xcg92
 Xildoff
Xildon
Xlibmieee
Xlibmil
 Xlibmopt
Xlicinfo
XMerge
Xnolib
 Xpg
Xprofile=p
 -xprofileValues
 Xregs=r
Example -xregs=appl,no%float
 Xsbfast
Xsafe=mem
Xsb
 Xspace
Xtarget=t
 XtargetExpansions
 Pascal 4.0 User’s Guide
 Pascal Compiler
 Ztext
 Program Construction Management
Units
 Using Program Units and Module Units
 Program Construction and Management
Compiling with Units
Hostname% pc programunit.p moduleunit.p
 Using Units and Header Files
 Sharing Variables Between Units
 Here is a program unit that declares a variable
 Program Construction and Management
 Libraries
 Separate Compilation
Working with Units
 Sharing Variables and Routines Across Multiple Units
Using Program Units
Using Module Units
 Compiling without the -xlOption
Sharing Public Variables
Program unit
Separate Compilation
 Using extern Option to Share Routines
Using include Files to Share Variables and Routines
 Commands to compile and execute incprog.p and incmod.p
Program unit, incprog.p, which includes the file
Module unit, incmod.p, which also includes the file
Hostname% pc incprog.p incmod.p
 Using the -xlOption
Using public var Declarations
 Commands to compile and execute pubvarprog.p and pubvarmod.p
 Using the define Variable Attribute
 Using the define Declaration
Commands to compile and execute defvarprog.p and defvarmod.p
 Using include Files
Module unit
 Program unit, incprog2.p Module unit, incmod2.p
 Program unit, extprog.p
Using extern
Commands to compile and execute incprog2.p and incmod2.p
 Module unit, extmod.p
Commands to compile and execute extprog.p and extmod.p
Sharing Declarations in Multiple Units
 Pascal 4.0 User’s Guide
 C-Pascal Interface
Compilation of Mixed-Language Programs
 Compatibility of Types for C and Pascal
Hostname% cc -c myc.c Hostname% pc -calign myc.o mypascal.p
 C-Pascal Interface
Precautions with Compatible Types
Character Strings
 Incompatibilities
Array Indexes
Aggregate Types
Enumerated Types
 Pascal Set Types
Procedure Calls C-Pascal
General Parameter Passing in C and Pascal
 Commands to compile and execute Samp.p
Variable Parameters
 Pascal procedure, SimVar.p
Simple Types without -xl
 Commands to compile and execute SimVar.p and SimVarMain.c
Pascal procedure
Simple Types with -xl
Strings of Characters
 C main program
Commands to compile and execute StrVar.p and StrVarMain.c
Fixed Arrays
 Pascal procedure, FixVec.p
Commands to compile and execute FixVec.p and FixVecMain.c
 Day =
 Univ Arrays
100
 Conformant Arrays
C-Pascal Interface 101
 Example 1 Single-Dimension Array
102
 Example 2 Multi-Dimension Array
C-Pascal Interface 103
 Example 3 Array of Characters
104
 Records and Structures
C-Pascal Interface 105
 Commands to compile and execute StruChr.p and StruChrMain.c
106
 Pascal routine
C-Pascal Interface 107
 Variant Records
108
 Commands to compile and execute VarRec.p and VarRecMain.c
C-Pascal Interface 109
 Pascal Set Type
110
 Pascal intset Type
C-Pascal Interface 111
 Value Parameters
112
 Commands to compile and execute SimVal.p and SimValMain.c
C-Pascal Interface 113
 Arrays
114
 Function Return Values
Simple Types
Pascal function
C-Pascal Interface 115
 Commands to compile and execute RetReal.p and RetRealMain.c
Pascal procedure, IO.p C main program, IOMain.c
Input and Output
116
 Procedure Calls Pascal-C
Hostname% cc IO.o IOMain.c -lpc
C function, SimRef.c
C-Pascal Interface 117
 118
 C-Pascal Interface 119
C function, StrVar.c
Pascal main program, StrVarMain.p
 120
Commands to compile and execute StrVar.c
Incorrect use of string in static variable storage
 Commands to compile and execute FixVec.c
C function, FixVec.c
Pascal main program
C-Pascal Interface 121
 C function, UniVec.c
122
 C function, IntCA.c
C-Pascal Interface 123
 124
Commands to compile and execute IntCA.c and IntCAMain.p
C function, StruChr.c
 Commands to compile and execute StruChr.c and StruChrMain.p
StruChr.c
Calign StruChr.o StruChrMain.p
Out
 C function, VarRec.c
126
 C-Pascal Interface 127
Non-Pascal Procedures
Commands to compile and execute VarRec.c
 128
 C function, SimVal.c
C-Pascal Interface 129
 Commands to compile and execute SimVal.c
130
 Parameters That Are Pointers to Procedures
Commands to compile and execute RetReal.c and RetRealMain.p
C function, RetReal.c
C function, ProcPar.c
 Procedures and Functions as Parameters
132
 C-Pascal Interface 133
Pascal procedure, GloVar.p
Global Variables in C and Pascal
 134
C procedure, UseFilePtr.c
File-Passing Between Pascal and C
 C-Pascal Interface 135
 136
 C++-Pascal Interface
Sample Interface
 Procedure Calls C++-Pascal
Pascal procedure, Samp, in the file, Samp.p
Compatibility of Types for C++ and Pascal
++ Name Encoding
 Arguments Passed by Reference
C++ main program, SampMain.cc
Hostname% pc -c Samp.p
C++-Pascal Interface 139
 140
Pascal procedure, SampRef, in the file, Samp.p
Simple Types without the -xlOption
 Commands to compile and execute SamRef.p and SamRefMain.cc
Simple Types with the -xlOption
C++ main program
Hostname% pc -c SamRef.p
 142
 C++-Pascal Interface 143
Commands to compile and execute StrRef.p and StrRefMain.cc
Hostname% pc -c StrRef.p
 Hostname% pc -c FixVec.p
144
 C++-Pascal Interface 145
 146
-calignoption
Hostname% pc -c DaysOfWeek.p
 C++-Pascal Interface 147
Commands to compile and execute StruChr.p
Hostname% pc -c StruChr.p
 148
 C++-Pascal Interface 149
 Arguments Passed by Value
Hostname% pc -c DayWeather.p
Hostname% pc -calign -c DayWeather.p
150
 C++-Pascal Interface 151
 Commands to compile and execute SimVal.p
152
 C++-Pascal Interface 153
Commands to compile and execute RetReal.p
Hostname% pc -c RetReal.p
 Input and Output
Hostname% pc -c RetShortReal.p
Pascal function, IO.p
154
 Procedure Calls Pascal-C++
C++ main program, IOMain.cc
Hostname% CC IO.o IOMain.cc -lpc hostname% a.out
C++-Pascal Interface 155
 156
Simple Types Passed by Reference
C++ function, SimRef.cc
 C++-Pascal Interface 157
 C++ function, SimVal.cc
158
 Commands to compile and execute SimVal.cc
C++-Pascal Interface 159
 C++ function, RetReal.cc
160
 Pascal procedure, GloVar.p C++ main program, GloVarMain.cc
Commands to compile and execute GloVar.p and GloVarMain.cc
Global Variables in C++ and Pascal
C++-Pascal Interface 161
 162
C++ procedure
Pascal File Pointers to C++
 FORTRAN-Pascal Interface
Compiler Mixed-Language Programs
 Compatibility of Types for Fortran and Pascal
164
 Real Integer Integer*2
FORTRAN-Pascal Interface 165
 166
 FORTRAN-Pascal Interface 167
Multidimensional Arrays
General Parameter-Passing in Fortran and Pascal
 Procedure Calls FORTRAN-Pascal
168
 FORTRAN-Pascal Interface 169
Commands to compile and execute SimVar.p
Fortran main program
 170
Pascal procedure, StrVar.p
Fortran main program, StrVarmain.f
 FORTRAN-Pascal Interface 171
Commands to compile and execute StrVar.p and StrVarmain.f
Fortran main program, FixVecmain.f
 Commands to compile and execute FixVec.p
172
 Commands to compile and execute UniVec.p and UniVecmain.f
FORTRAN-Pascal Interface 173
 Commands to compile and execute IntCA.p
174
 FORTRAN-Pascal Interface 175
Commands to compile and execute ChrCA.p
Fortran main program, ChrCAmain.f
 176
 FORTRAN-Pascal Interface 177
 178
 FORTRAN-Pascal Interface 179
 180
 FORTRAN-Pascal Interface 181
 Commands to compile and execute SimVal.p and SimValmain.f
182
 Pascal procedure, ChrCAx.p
Commands to compile and execute ChrCAx.p
Pointers
FORTRAN-Pascal Interface 183
 Commands to compile and execute PastPtr.p
184
 FORTRAN-Pascal Interface 185
Procedure Calls Pascal-FORTRAN
Fortran main program, RetRealmain.f
 Fortran subroutine
186
 FORTRAN-Pascal Interface 187
 Fortran subroutine, StrVar.f
188
 Commands to compile and execute StrVar.f and StrVarmain.p
Character Dummy Arguments
Hostname% f77 -c StrVar.f
Hostname% pc StrVar.o StrVarmain.p -lpfc -lF77
 Following example illustrates this method
190
 Commands to compile and execute FixVec.f
FORTRAN-Pascal Interface 191
 192
Fortran subroutine, UniVec.f
Pascal main program, UniVecmain.p
 FORTRAN-Pascal Interface 193
Commands to compile and execute UniVec.f and UniVecmain.p
Hostname% f77 -c UniVec.f
 Fortran subroutine, StruChr.f
194
 Commands to compile and execute StruChr.f and StruChrmain.p
Hostname% f77 -c StruChr.f
Hostname% pc StruChr.o StruChrmain.p -lpfc -lF77
FORTRAN-Pascal Interface 195
 196
 FORTRAN-Pascal Interface 197
 198
 FORTRAN-Pascal Interface 199
 200
 Commands to compile and execute PassPtr.f and PassPtrmain.p
Hostname% f77 -c PassPtr.f
Hostname% pc PassPtr.o PassPtrmain.p -lpfc -lF77
Fortran function, RetReal.f
 202
Commands to compile and execute RetReal.f and RetRealmain.p
Routines as Parameters
 FORTRAN-Pascal Interface 203
 204
 Illegal Characters
Error Diagnostics
Compiler Syntax Errors
 206
String Errors
Digits in Real Numbers
 Hostname% pc synerr.p
Replacements, Insertions, and Deletions
Error Diagnostics 207
 208
Expected Symbols and Malformed Constructs
Undefined or Improper Identifiers
 Error Diagnostics 209
Expected and Unexpected End-of-file
Hostname% pc synerr2.p
Pascal program, mism.p
 Compiler Semantic Errors
Format of the Error Diagnostics
Incompatible Types
210
 Scalar Class
Procedure and Function Type Errors
Error Diagnostics 211
 212
Scalar Error Messages
Expression Diagnostics
 This program generates the following error messages
Error Diagnostics 213
 Type Equivalence
214
 Pascal program, unreached.p
Error Diagnostics 215
Unreachable Statements
 Goto Statement
Uninitialized Variables
Unused Variables, Constants, Types, Labels, and Routines
Hostname% pc unreached.p
 Error Diagnostics 217
Compiler Panics, I/O Errors
Runtime Errors
 218
 Error Diagnostics 219
 220
 XView Toolkit
Overview
 Tools
Objects
Object-Oriented Programming
222
 XView Toolkit 223
Pascal Interface
Drawable Object Window Icon
 Attribute Procedures
Compiling with Libraries
Header Files
Names
 Attribute Lists
XView Toolkit 225
 Handles
Data Types
Here, mymenu is an object of type XVobject
226
 Conversion of C to Pascal
Coding Fragment
An Example
XView Toolkit 227
 Pascal
228
 Sample Translation of an XView Function to Pascal
XView Toolkit 229
 Sample Program
230
 Menu Demo Program
XView Toolkit 231
 Panelbutton
232
 Math Libraries
 Contents of the Math Libraries
 Libm Functions
Math Libraries 235
 Ieee Support Functions
236
 Math Libraries 237
Ieeefunctions
Ieeevalues
 238
Sparc Libraries
Ieeeretrospective
 Arithmetic Exceptions
Math Libraries 239
 Math Library Exception-Handling Function matherr
240
 Math Libraries 241
 Libsunmath Support for Ieee Modes and Exceptions
242
 Math Libraries 243
 244
 Pascal Preprocessor
Conditional Variables
 Compiler Directives
246
 %config Directive
Pascal Preprocessor 247
 Hostname% pc -xl config.p hostname% a.out
248
 Output when you define two
Output when you define foo
%debug Directive
Pascal Preprocessor 249
 250
%else Directive
Hostname% pc -xl -cond debug.p hostname% a.out
 Hostname% pc -xl -config red ifthenelse.p hostname% a.out
%elseif Directive
Pascal program, ifthenelse.p
Pascal Preprocessor 251
 Hostname% pc -xl -config blue elseif.p hostname% a.out
%elseifdef Directive
Pascal program
252
 Pascal Preprocessor 253
 254
%enable Directive
Hostname% pc -xl -config bird2 ifdef.p hostname% a.out
 %error Directive
Hostname% pc -xl enable.p hostname% a.out
%endif Directive
Pascal Preprocessor 255
 256
Error.p
%exit Directive
 Pascal Preprocessor 257
%if Directive
Hostname% pc -xl exitdirective.p hostname% a.out
 %ifdef Directive
258
 %include Directive
Pascal Preprocessor 259
 260
%list Directive
Module unit, includemod.p
 Pascal program, list.p
Pascal Preprocessor 261
 262
%nolist Directive
List.p
 %slibrary Directive
%var Directive
%warning Directive
Pascal Preprocessor 263
 264
Output when you compile warning.p without the -configoption
Pc -xl warning.p
 Error Messages
 266
 Error Messages 267
Fourth argument to function must be of type type, not type
 268
 Error Messages 269
 Function requires a to be an unpacked array, not type
270
 Error Messages 271
 272
 Error Messages 273
 274
 Error Messages 275
Identifier
 Unknown option for procedure pointer ignored option
276
 Error Messages 277
 278
 Error Messages 279
 280
 Error Messages 281
 Cannot mix sets with integers and reals as operands of type
282
 Error Messages 283
 284
 Error Messages 285
 286
 Error Messages 287
 288
 Error Messages 289
Multiply defined label in case, lines number and number
 290
 Error Messages 291
 292
 Error Messages 293
 OUT
294
 Error Messages 295
 296
 Index
297
 298
 Index 299
 300
 Index 301
 302
 Index 303
 304
 Index 305
 306
 Index 307
 Marques