Pascal 4.0 User’s GuidePart No.: 802-2943-10Revision A, November 1995A Sun Microsystems, Inc. Business2550 Garcia AvenueMountain View, CA 94043U.S.A.
x Pascal 4.0 User’s GuideFunction Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Parameters That Are Pointers to Procedur
76 Pascal 4.0 User’s Guide5Using Program UnitsThe program unit is the source program with the program header. It has thefollowing syntax:<program
Separate Compilation 775Compiling without the -xl OptionThere are three ways of sharing variables and routines across units when youcompile your progr
78 Pascal 4.0 User’s Guide5Using extern Option to Share RoutinesIf a program or module calls a procedure not defined in that unit, you mustdeclare it w
Separate Compilation 795The program unit, inc_prog.p,which includes the fileinclude.hprogram inc_prog;#include "include.h"begin { program bod
80 Pascal 4.0 User’s Guide5Using the -xl OptionWhen you use the –xl option, variables and top-level procedures andfunctions declared in the program un
Separate Compilation 815The program unit,pubvar_prog.p, which declaresglobal as publicprogram pubvar_prog;public var global: integer;procedure proc
82 Pascal 4.0 User’s Guide5Using the define Variable AttributeThis example makes global public using the define attribute of the variabledeclaration.Th
Separate Compilation 835Using the define DeclarationThis example defines global in the module defvar_mod2 using the definedeclaration. The advantage o
84 Pascal 4.0 User’s Guide5Using include FilesIn the following example, the extern declaration for the variable global is inthe include file, inc_prog2
Separate Compilation 855The program unit, inc_prog2.p program inc_prog2;%include "include2.h";procedure proc; extern;begin global := 1;
Contents xiGeneral Parameter-Passing in FORTRAN and Pascal. . . . . . . . 167Procedure Calls: FORTRAN-Pascal. . . . . . . . . . . . . . . . . . . . .
86 Pascal 4.0 User’s Guide5Using externIn the previous example, the extern definition for variables is put into aninclude file and then shared. You can
Separate Compilation 875Sharing Declarations in Multiple UnitsUsing extern and external directives for procedure and functiondeclarations, you can opt
88 Pascal 4.0 User’s Guide5For routines declared extern fortran or external fortran, the changesin the calling sequence are as follows:• For value par
89The C–Pascal Interface6This chapter describes how to mix C and Pascal modules in the same program.It contains the following sections:The examples in
90 Pascal 4.0 User’s Guide6The -c option produces an unlinked object file. The -calign option causespc to use C-like data formats for aggregate object
The C–Pascal Interface 916Precautions with Compatible TypesThis section describes the precautions you should take when working withcompatible types.Th
92 Pascal 4.0 User’s Guide6Array IndexesPascal array indexes can start at any integer; C array indexes always start atzero.Aggregate TypesAggregate ty
The C–Pascal Interface 936Pascal Set TypesIn Pascal, a set type is implemented as a bit vector, which is similar to a Cshort-word array, where each sh
94 Pascal 4.0 User’s Guide6Variable ParametersPascal passes all variable parameters by reference, which C can do, too.The C main program,SampMain.c.
The C–Pascal Interface 956Simple Types without –xlWithout -xl, simple types match, as in the following example:The Pascal procedure,SimVar.pprocedure
xii Pascal 4.0 User’s GuideThe scalar Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Procedure and Function Type Errors.
96 Pascal 4.0 User’s Guide6Simple Types with –xlWith the -xl option, the Pascal real must be paired with a C float, and thePascal integer must be pair
The C–Pascal Interface 976Fixed ArraysFor a fixed array parameter, pass the same type and size by reference, asshown in the following example:The C mai
98 Pascal 4.0 User’s Guide6Although it does not apply in this example, arrays of aggregates in Pascalhave, by default, a size that is always a multipl
The C–Pascal Interface 996The Pascal procedure,DaysOfWeek.ptypeTDay= array [0..8] of char;TWeek = array [0..6] of day;TYear = array [0..51] of week;pr
100 Pascal 4.0 User’s Guide6The univ ArraysYou can pass any size array to a Pascal procedure expecting a univ array,although there is no special gain
The C–Pascal Interface 1016Conformant ArraysFor single-dimension conformant arrays, pass upper and lower bounds, placedafter the declared parameter li
102 Pascal 4.0 User’s Guide6Examples of single-dimension, multidimension, and array-of-characterconformant arrays follow. Conformant arrays are inclu
The C–Pascal Interface 1036Example 2: Multi-Dimension ArrayThe Pascal procedure,RealCA.p. Pascal passes lowbound, high bound, and elementwidth.proced
104 Pascal 4.0 User’s Guide6If wc is the width of the smallest element, as determined by sizeof(), thenthe width of the next largest element is the nu
The C–Pascal Interface 1056Records and StructuresIn most cases, a Pascal record describes the same objects as its C structureequivalent, provided that
Contents xiiiAn Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227Sample Translation of an XView Function to Pa
106 Pascal 4.0 User’s Guide6The record in the example above has, by default, the same size and alignmentas the equivalent C record. Some records, tho
The C–Pascal Interface 1076Consider this example:The Pascal routine,DayWeather.ptype TDayWeather = recordTDay: array [0..8] of char;TWeather: array
108 Pascal 4.0 User’s Guide6When you compile the Pascal routine without using the -calign option, theprogram does not work correctly.Variant RecordsC
The C–Pascal Interface 1096The C main program,VarRecMain.c#include <stdio.h> struct vlr { char tag; union { struct {
110 Pascal 4.0 User’s Guide6Pascal Set TypeIn Pascal, a set type is implemented as a bit vector, which is similar to a Cshort-word array. Direct acce
The C–Pascal Interface 1116Pascal intset TypeThe Pascal intset type is predefined as set of [0..127]. A variable ofthis type takes 16 bytes of storage
112 Pascal 4.0 User’s Guide6Value ParametersThere are three types of value parameters in Pascal.Simple Types without –xlWithout –xl, simple types matc
The C–Pascal Interface 1136If no function prototype is provided for SimVal in SimValMain.c, thensr:shortreal must be changed to sr:real in SimVal.p.
114 Pascal 4.0 User’s Guide6ArraysSince C cannot pass arrays by value, it cannot pass strings of characters, fixedarrays, or univ arrays by value.Confo
The C–Pascal Interface 1156Function Return ValuesFunction return values match types the same as with parameters, and theypass in much the same way.Sim
xiv Pascal 4.0 User’s Guide
116 Pascal 4.0 User’s Guide6Input and OutputIf your C main program calls a Pascal procedure that does I/O, then includethe following code in the C mai
The C–Pascal Interface 1176Procedure Calls: Pascal–CThis section parallels the section, “Procedure Calls: C–Pascal” on page 93.Earlier comments and re
118 Pascal 4.0 User’s Guide6Strings of CharactersThe alfa and string types pass simply; varying strings are morecomplicated. All pass by reference.Th
The C–Pascal Interface 1196The C function, StrVar.c #include <string.h>struct TVarLenStr { int nbytes; char a[26];};void StrVar(char *s10,
120 Pascal 4.0 User’s Guide6Avoid constructs that rely on strings being in static variable storage. Forexample, you could use mktemp(3) in Pascal as
The C–Pascal Interface 1216Fixed ArraysFor a fixed-array parameter, pass the same type and size, as in this example:The -calign option is not needed fo
122 Pascal 4.0 User’s Guide6The univ ArraysThe univ arrays that are in, out, in out, or var parameters pass byreference.Here is an example:The C funct
The C–Pascal Interface 1236The -calign option is not needed for this example, but may be necessary ifthe array parameter is an array of aggregates.Con
124 Pascal 4.0 User’s Guide6The -calign option is not needed for this example, but may be necessary ifthe array parameter is an array of aggregates.Re
The C–Pascal Interface 1256Variant RecordsC equivalents of variant records can sometimes be constructed, although thereis some variation with the arch
xvFiguresFigure 3-1 Organization of Pascal Compilation. . . . . . . . . . . . . . . . . . . . . . 19Figure 3-2 Options in Program Text . . . . . . . .
126 Pascal 4.0 User’s Guide6Following are some examples:The C function, VarRec.c struct vlr { char tag; union {struct { char ch1, ch2;} a_var
The C–Pascal Interface 1276The -calign option is not needed in the previous example, but may benecessary if the record contains aggregates.Non-Pascal
128 Pascal 4.0 User’s Guide6See this example:The C function, NonPas.c. Inthe function for_C, s is apointer (declared var in theprocedure declaration)
The C–Pascal Interface 1296Value ParametersIn general, Pascal passes value parameters in registers or on the stack,widening to a full word if necessar
130 Pascal 4.0 User’s Guide6Function Return ValuesFunction return values match types in the same manner as with parameters,and they pass in much the s
The C–Pascal Interface 1316Parameters That Are Pointers to ProceduresPascal has a special type that is a pointer to a procedure. A variable of thisty
132 Pascal 4.0 User’s Guide6Procedures and Functions as ParametersIt is probably clearer to pass a pointer to a procedure than to pass theprocedure na
The C–Pascal Interface 1336functions can be passed to other languages as arguments, the static links for allprocedure or function arguments are placed
134 Pascal 4.0 User’s Guide6File-Passing Between Pascal and CYou can pass a file pointer from Pascal to C, then have C do the I/O, as in:The commands t
The C–Pascal Interface 1356The commands to compile andexecute UseFilePtc.c andUseFilePtrMain.phostname% cc -c UseFilePtr.chostname% pc UseFilePtr.o Us
xvi Pascal 4.0 User’s Guide
136 Pascal 4.0 User’s Guide6
137The C++–Pascal Interface7This chapter describes how to mix C++ and Pascal modules in the sameprogram. It contains the following sections:Sample In
138 Pascal 4.0 User’s Guide7Compatibility of Types for C++ and PascalTable 6-1 and Table 6-2 on page 90 list the default sizes and alignments ofcompat
The C++–Pascal Interface 1397Arguments Passed by ReferenceC++ arguments can be passed by reference. This section describes how theywork with Pascal.T
140 Pascal 4.0 User’s Guide7Simple Types without the -xl OptionWithout the -xl option, simple types match, as in the following example:The Pascal proc
The C++–Pascal Interface 1417Simple Types with the -xl OptionWith the -xl option, the Pascal real must be paired with a C++ float; thePascal integer
142 Pascal 4.0 User’s Guide7Strings of CharactersThe C++ counterpart to the Pascal alfa and string types are arrays. The C++counterpart to the Pascal
The C++–Pascal Interface 1437The C++ main program,StrRefMain.cc#include <stdio.h>#include <string.h> struct TVarLenStr { int NBytes;
144 Pascal 4.0 User’s Guide7Fixed ArraysThe Pascal procedure,FixVec.ptype TVec = array [0..8] of integer;procedure FixVec ( var V: TVec; var Sum: i
The C++–Pascal Interface 1457Although it does not apply to this example, arrays of aggregates in Pascalhave, by default, a size that is a multiple of
xviiTablesTable 3-1 File Name Suffixes Recognized by Pascal . . . . . . . . . . . . . . . . . 20Table 3-2 Options That Can Be Passed in Program Text
146 Pascal 4.0 User’s Guide7Records and StructuresA Pascal record of an integer and a character string matches a C++ structure ofthe same constructs,
The C++–Pascal Interface 1477The C++ main program,StruChrMain.cc#include <stdio.h>#include <string.h> struct TVarLenStr { int NBytes;
148 Pascal 4.0 User’s Guide7Consider this example:The Pascal procedure,DayWeather.ptype TDayWeather = record TDay: array [0..8] of char; TWeat
The C++–Pascal Interface 1497The C++ main program,DayWeatherMain.cc#include <stdio.h>#include <string.h> struct TDayRec { char TDay[9]
150 Pascal 4.0 User’s Guide7Arguments Passed by ValueC++ arguments can be passed by value. In this section, we describe how theywork with Pascal.When
The C++–Pascal Interface 1517Simple Types without the -xl OptionWithout the -xl option, simple types match, as in the following example:The Pascal pro
152 Pascal 4.0 User’s Guide7Function Return ValuesFunction return values match types in the same manner as with parameters.They pass in much the same
The C++–Pascal Interface 1537Simple TypesSimple types pass in a straightforward way, as in the following example:The Pascal function,RetReal.pfunction
154 Pascal 4.0 User’s Guide7Type shortrealInput and OutputThe Pascal function,RetShortReal.pfunction RetShortReal (r: shortreal): shortreal;begin Ret
The C++–Pascal Interface 1557Procedure Calls: Pascal–C++A Pascal main program can also call C++ functions. The following examplesshow you how to pass
xviii Pascal 4.0 User’s GuideTable 10-1 C Declarations to Pascal Declarations . . . . . . . . . . . . . . . . . . . . 228Table 11-1 Contents of Math L
156 Pascal 4.0 User’s Guide7Simple Types Passed by ReferenceSimple types pass in a straightforward manner, as follows:The C++ function, SimRef.cc exte
The C++–Pascal Interface 1577Arguments Passed by ValuePascal arguments can also be passed by value. Here is how they work withC++.The Pascal main pro
158 Pascal 4.0 User’s Guide7Simple TypesSimple types match with value parameters. See the following example:The C++ function, SimVal.cc extern "
The C++–Pascal Interface 1597Function Return ValuesFunction return values match types in the same manner as with parameters.They pass in much the same
160 Pascal 4.0 User’s Guide7The following example shows how to pass simple types:The C++ function, RetReal.cc extern "C"double RetReal (doub
The C++–Pascal Interface 1617Global Variables in C++ and PascalIf the types are compatible, a global variable can be shared between C++ andPascal. Se
162 Pascal 4.0 User’s Guide7Pascal File Pointers to C++You can pass a file pointer from Pascal to C++, then have C++ do the I/O. Seethis example.The C
163The FORTRAN–Pascal Interface8This chapter describes how to mix FORTRAN 77 and Pascal modules in thesame program. It contains the following section
164 Pascal 4.0 User’s Guide8Specify –lpfc on the command-line before –lpc. For example:The -c option to pc produces an unlinked object file.When you c
The FORTRAN–Pascal Interface 1658Table 8-2 lists the default sizes and alignments of compatible types forFORTRAN and Pascal with the -xl option:Precau
xixPrefaceThis manual describes the Pascal 4.0 compiler from SunSoft™. The purpose ofthis manual is to help you begin writing and compiling Pascal pr
166 Pascal 4.0 User’s Guide8Character StringsThere are some precautions to take with character strings regarding the nullbyte, passing by value, and s
The FORTRAN–Pascal Interface 1678Pascal Set TypesIn Pascal, a set type is implemented as a bit vector, which is similar to aFORTRAN 16-bit word. Dire
168 Pascal 4.0 User’s Guide8Procedure Calls: FORTRAN-PascalHere are examples of how a FORTRAN main program calls a Pascal procedure.Variable Parameter
The FORTRAN–Pascal Interface 1698See the following example:The Pascal procedure,SimVar.pprocedure simvar_(var t, f: boolean; var c: char;
170 Pascal 4.0 User’s Guide8Simple Types with the –xl OptionWhen you pass the -xl option, the Pascal data type real must be paired witha FORTRAN data
The FORTRAN–Pascal Interface 1718Fixed ArraysFor a fixed array parameter, pass the same type and size by reference, asshown in the following example:Th
172 Pascal 4.0 User’s Guide8The univ ArraysYou can pass any size array to a Pascal procedure expecting a univ array, butthere is no advantage in doing
The FORTRAN–Pascal Interface 1738Conformant ArraysFor conformant arrays, with single-dimension array, pass upper and lowerbounds, placed after the dec
174 Pascal 4.0 User’s Guide8Example 1: Single-Dimension ArrayExample 2: Array of CharactersThe Pascal procedure,IntCA.p. Pascal passes thebounds by v
The FORTRAN–Pascal Interface 1758Records and StructuresIn most cases, a Pascal record describes the same objects as its FORTRANstructure equivalent, p
PleaseRecycle 1995 Sun Microsystems, Inc. 2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.All rights reserved. This product or documen
xx Pascal 4.0 User’s GuideAudienceThis guide was prepared for software engineers who write Pascal programs ona SPARCstation. It assumes you are famil
176 Pascal 4.0 User’s Guide8A Pascal record of an integer and a character string matches a FORTRANstructure of the same. Consider these examples:The
The FORTRAN–Pascal Interface 1778Variant RecordsFORTRAN equivalents of variant records can sometimes be constructed,although there is some variation w
178 Pascal 4.0 User’s Guide8The FORTRAN main program,VarRecmain.f. The variableALIGN is integer*2, and isneeded to match the Pascalvariant record lay
The FORTRAN–Pascal Interface 1798Pascal Set TypeThe Pascal set type is incompatible with FORTRAN.Pascalintset TypeThe Pascal intset type is predefined
180 Pascal 4.0 User’s Guide8Value ParametersIn general, Pascal passes value parameters on the stack.Simple Types without the –xl OptionWithout the -xl
The FORTRAN–Pascal Interface 1818See the following example:The Pascal procedure,SimVal.p. t, f, c, i, r, and sare value parameters.procedure simval_(t
182 Pascal 4.0 User’s Guide8Simple Types with the –xl OptionWith the -xl option, match Pascal real with FORTRAN real and Pascalinteger with FORTRAN in
The FORTRAN–Pascal Interface 1838PointersPointers are easy to pass, as shown in the following example:Pascal procedure, ChrCAx.p procedure chrca_ ( a:
184 Pascal 4.0 User’s Guide8Function Return ValuesFunction return values match types the same as with parameters, and theypass in much the same way.
The FORTRAN–Pascal Interface 1858Simple TypesThe simple types pass in a straightforward way, as follows:TypeshortrealThere is no problem with returnin
Preface xxi• Appendix B, “Error Messages,” lists all the error messages the compilerproduces.This guide concludes with an index.Conventions Used in T
186 Pascal 4.0 User’s Guide8Variable ParametersPascal passes all var parameters by reference, the FORTRAN default.Simple TypesSimple types pass in a s
The FORTRAN–Pascal Interface 1878Strings of CharactersThe alfa and string types pass simply; varying strings are a little tricky. Allpass by referenc
188 Pascal 4.0 User’s Guide8The FORTRAN subroutine,StrVar.f subroutine StrVar ( s10, s80, vls ) character s10*10, s80*80 struct
The FORTRAN–Pascal Interface 1898Character Dummy ArgumentsWhen you call FORTRAN 77 routines with character dummy arguments fromPascal programs—that is
190 Pascal 4.0 User’s Guide8The following example illustrates this method:The Pascal program, sun.pas program Test(input,output);var s : string;proc
The FORTRAN–Pascal Interface 1918Fixed ArraysFor a fixed-array parameter, pass the same type and size by reference:The FORTRAN subroutine,FixVec.f
192 Pascal 4.0 User’s Guide8The univ ArraysThe univ arrays that are in, out, in out, or var parameters pass byreference.The FORTRAN subroutine,UniVec.
The FORTRAN–Pascal Interface 1938Conformant ArraysPascal-conformant array parameters are not compatible if Pascal callsFORTRAN.The commands to compile
194 Pascal 4.0 User’s Guide8Records and StructuresRecords and structures pass as follows:The FORTRAN subroutine,StruChr.f subroutine StruChr (
The FORTRAN–Pascal Interface 1958Variant RecordsYou can construct FORTRAN equivalents of variant records. There is somevariation with architecture, a
xxii Pascal 4.0 User’s GuideShell Prompts in Command ExamplesThe following table shows the default system prompt and superuser promptfor the C shell,
196 Pascal 4.0 User’s Guide8Chapter 6, “The C–Pascal Interface,” has an example that matches thefollowing example.The FORTRAN subroutine,VarRec.f. Th
The FORTRAN–Pascal Interface 1978Value ParametersWith external fortran on the procedure statement, Pascal passes valueparameters as FORTRAN expects th
198 Pascal 4.0 User’s Guide8Simple TypesWith external fortran, the procedure name in the procedure statementand in the call must be in lowercase, with
The FORTRAN–Pascal Interface 1998The Pascal main program,SimValmain.pprogram SimVal(output);var t: boolean := true; f: boolean := false; c: c
200 Pascal 4.0 User’s Guide8PointersPointers are easy to pass, as shown in the following example:The FORTRAN subroutine,PassPtr.f. In the FORTRANsubr
The FORTRAN–Pascal Interface 2018Function Return ValuesFunction return values match types the same as with parameters, and theypass in much the same w
202 Pascal 4.0 User’s Guide8Type shortrealYou can return a shortreal function value between Pascal and FORTRAN.Pass it exactly as in the previous exam
The FORTRAN–Pascal Interface 2038If the procedure is not a top-level procedure, then you do not deal with how topass it, because that requires allowin
204 Pascal 4.0 User’s Guide8Routines in other languages can be passed to Pascal; a dummy argument mustbe passed in the position normally occupied by t
205Error Diagnostics9This chapter discusses the errors you may come across while writing softwareprograms with Pascal. It contains the following sect
Preface xxiiiREADME FilesThe README default directory is: /opt/SUNWspro/READMEs.This directory contains the following files:• A Pascal 4.0 README, call
206 Pascal 4.0 User’s Guide9Most nonprinting characters in your input are also illegal, except in characterconstants and character strings. Except fo
Error Diagnostics 2079Replacements, Insertions, and DeletionsWhen Pascal encounters a syntax error in the input text, the compiler invokesan error rec
208 Pascal 4.0 User’s Guide9Undefined or Improper IdentifiersIf an identifier is encountered in the input but is undeclared, the error recoverymechanism
Error Diagnostics 2099Expected and Unexpected End-of-fileIf pc finds a complete program, but there is more (noncomment) text in theinput file, then it in
210 Pascal 4.0 User’s Guide9Compiler Semantic ErrorsThe following sections explain the typical formats and terminology used inPascal error messages.Fo
Error Diagnostics 2119Thus, if you try to assign an integer value to a char variable, you receive adiagnostic as follows:In this case, one error produ
212 Pascal 4.0 User’s Guide9Scalar Error MessagesError messages stating that scalar (user-defined) types cannot be read from andwritten to files are oft
Error Diagnostics 2139This program generates the following error messages:program expr_example(output);var a: set of char; b: Boolean; c: (re
214 Pascal 4.0 User’s Guide9Type EquivalenceThe Pascal compiler produces several diagnostics that generate the followingmessage:non-equivalent typesIn
Error Diagnostics 2159To make the assignment statement work, you must declare a type and use it todeclare the variables, as follows:Alternatively, you
xxiv Pascal 4.0 User’s GuideNumerical Computation Guide X (AnswerBook)README X (CD-ROM)What Every Scientist Should Know About Floating-Point Arithmeti
216 Pascal 4.0 User’s Guide9A statement is considered to be reachable if there is a potential path of control,even if it cannot be taken. Thus, no di
Error Diagnostics 2179If you declare a label but never use it, Pascal gives you a warning. This is trueeven for a label declared in global scope.Comp
218 Pascal 4.0 User’s Guide9<filename> : Bad data found on enumerated read<filename> : Bad data found on integer read<filename> : Bad d
Error Diagnostics 2199Argument to argv of <number> is out of rangeAssertion #<number> failed: <assertion message>Cannot close null f
220 Pascal 4.0 User’s Guide9Pointer value (<number>) out of legal rangeRan out of memoryRange lower bound of <number> out of set boundsRan
221The XView Toolkit10This chapter introduces the XView programmer’s toolkit, a part of the XViewapplication programmer’s interface (API). It assumes
222 Pascal 4.0 User’s Guide10ToolsThis kit is a collection of functions. The runtime system is based on eachapplication having access to a server-bas
The XView Toolkit 22310with the root being the class from which all others are descended. In theXView toolkit, the root is the class Generic Object,
224 Pascal 4.0 User’s Guide10Compiling with LibrariesMost XView procedures you call are in the libraries pxview, xview, and X11.To compile an XView pr
The XView Toolkit 22510Instead of these routines, the Pascal interface to XView defines a separateroutine to get and set each attribute.• set—The routi
1Introduction1This chapter gives an overview of the features of Pascal, includingcompatibility, internationalization, and licensing. It contains the
226 Pascal 4.0 User’s Guide10Example calls are:The lists for Attr_avlist are created by functions that have the followingnames:attr_create_list_n()att
The XView Toolkit 22710Coding FragmentHere is an example that illustrates the style of programming with the XViewinterface in Pascal. This program:•
228 Pascal 4.0 User’s Guide10The Straightforward Part—You can use the following items of information asyou find them in the manual, with no change:• Th
The XView Toolkit 22910Sample Translation of an XView Function to PascalIn the section, “Summary of Procedures and Macros,” in the XViewProgramming Ma
230 Pascal 4.0 User’s Guide10Sample ProgramThe following program, xview.p, makes a window:To compile xview.p and link in the necessary libraries, use
The XView Toolkit 23110Menu Demo ProgramHere is a more complicated program, menu_demo.p, that makes a windowand a panel with a menu button. The choic
232 Pascal 4.0 User’s Guide10To compile menu_demo.p and link in the necessary libraries, use the followingcommand-line:hostname% pc menu_demo.p -Ipasc
233Math Libraries11This chapter describes how to use the libm and libsunmath functions inPascal programs. The math libraries are always accessible fr
234 Pascal 4.0 User’s Guide11Contents of the Math LibrariesAltogether, there are three math libraries:• libm.a—A set of functions required by the vari
Math Libraries 23511Legend:mFunctions available in bundled libmm+Functions available in bundled libm and as single-precision version onlyin libsunmath
2 Pascal 4.0 User’s Guide1Pascal CompilerThe name of the Pascal compiler is pc. If given an argument file name endingwith .p or .pas, pc compiles the
236 Pascal 4.0 User’s Guide11The following Pascal program is an example of how to use math functions.IEEE Support FunctionsThis section describes the
Math Libraries 23711ieee_functions()The functions described in ieee_functions(3M) provide capabilities eitherrequired by the IEEE standard or recommen
238 Pascal 4.0 User’s Guide11ieee_retrospective()The libm function ieee_retrospective() prints to stderr informationabout unrequited exceptions and no
Math Libraries 23911Arithmetic ExceptionsAn arithmetic exception arises when an attempted atomic arithmetic operationdoes not produce an acceptable re
240 Pascal 4.0 User’s Guide11• Division by zero—The divisor is zero, and the dividend is a finite non-zeronumber; or, more generally, an exact infinite
Math Libraries 24111If your matherr() function returns a non-zero result, no exception message isprinted, and errno is not set.DOMAIN Argument domain
242 Pascal 4.0 User’s Guide11libsunmath Support for IEEE Modes and Exceptionsieee_handler() is used primarily to establish a signal handler for aparti
Math Libraries 24311The syntax of this function is described in the ieee_flags(3M) man page.If an exception is raised at any time during program execu
244 Pascal 4.0 User’s Guide11
245Pascal PreprocessorAThis appendix describes the preprocessors, cpp(1) and cppas.cppcpp(1) is the C language preprocessor. Pascal runs your source
Introduction 31Text EditorsThe operating system provides two main editors:• Text Editor—A window-based text editor that runs in the OpenWindowsenviron
246 Pascal 4.0 User’s GuideAA defined conditional variable is enabled (true) when it appears in either the%enable directive or in the –config option;
Pascal Preprocessor 247AThe rest of this appendix contains detailed descriptions and examples of eachdirective.The%config DirectiveThe %config directi
248 Pascal 4.0 User’s GuideAExampleThe Pascal program,config.p, which defines theconditional variables one andtwoprogram config_example(output);{ This
Pascal Preprocessor 249AThe %debug DirectiveThe %debug directive instructs pc to compile this line of code when you usethe –cond compiler directive.Sy
250 Pascal 4.0 User’s GuideAExampleThe %else DirectiveThe %else directive provides an alternative action to the %if directive.Syntax%if expression %th
Pascal Preprocessor 251AExampleThe %elseif DirectiveThe %elseif directive provides an alternative action to the %if directive.Syntax%if expression %th
252 Pascal 4.0 User’s GuideACommentsIf the expression in %if expression %then is false, pc skips over the %thenpart and executes the %elseif part inst
Pascal Preprocessor 253ASyntax%ifdef expression %then . .%elseifdef expression %then . .%endifCommentsIf the expression in %ifdef expr
254 Pascal 4.0 User’s GuideAThe %enable DirectiveThe %enable directive sets a conditional variable to true.Syntax%enable var1 ..., varNCommentsA define
Pascal Preprocessor 255AExampleThe %endif DirectiveThe %endif directive indicates the end of a %if or %ifdef directive. See thesections on %if and %i
4 Pascal 4.0 User’s Guide1InternationalizationA product can support up to four levels of internationalization:• Level 1—Allows native-language charact
256 Pascal 4.0 User’s GuideASyntax%error 'string'Commentspc does not produce an object file.ExampleThe%exit DirectiveThe %exit directive inst
Pascal Preprocessor 257ACommentsIf the compiler encounters an %exit directive within an include file, it stopsprocessing the include file, but continues
258 Pascal 4.0 User’s GuideACommentsWhen pc encounters a %if directive, it evaluates expression. If expression istrue, pc executes the statements in
Pascal Preprocessor 259ACommentsexpression consists of a conditional variable and the optional booleanoperators and, or, and not. See the %else listi
260 Pascal 4.0 User’s GuideAThe %list DirectiveThe %list directive enables a listing of the program.Syntax%list;The module unit,include_mod.pmodule in
Pascal Preprocessor 261ACommentsThe %list directive and the -l compiler option perform the same function.ExampleThe Pascal program, list.p program lis
262 Pascal 4.0 User’s GuideAThe %nolist DirectiveThe %nolist directive disables the program listing.Syntax%nolist;Comments%nolist is the default.Examp
Pascal Preprocessor 263AThe %slibrary Directivecppas treats %slibrary in the same manner as the %include directive. See“The %include Directive” on pa
264 Pascal 4.0 User’s GuideAExampleThe Pascal program,warning.pprogram warning_example(output);{ This program demonstrates the use of the %warning co
265Error MessagesBThe following is a list of the error messages produced by Pascal, arranged bymessage number.10010: Builtin <function> takes ex
Introduction 51If you reset your system locale to, for example, France, and rerun the program,the output is the same. Pascal does not replace the per
266 Pascal 4.0 User’s GuideB10120: Too many arguments to <function>10130: Actual argument cannot be conformant array10140: Actual argument is in
Error Messages 267B10290: Fourth argument to <function> must be of type <type>,not <type>10300: First argument to <function> c
268 Pascal 4.0 User’s GuideB10470: ord's argument must be of scalar type, not <type>10480: <function>'s argument must be of scal
Error Messages 269B10660: Second and successive arguments to <function> must beconstants10670: Argument to <function> must be a alfa, not
270 Pascal 4.0 User’s GuideB10840: Illegal argument with format radix specification;probably a comma missing11010: have incompatible conformant array
Error Messages 271B11170: For-statement variable <identifier> cannot be an elementof a record11180: . allowed only on records, not on <type>
272 Pascal 4.0 User’s GuideB12060: Width expressions allowed only in writeln/writecalls12070: Cannot write <type>s with two write widths12080: C
Error Messages 273B13070: constant argument expected13080: newline in string or char constant13090: empty character constant13100: too many characters
274 Pascal 4.0 User’s GuideB14140: PUBLIC ignored, procedure was declared INTERNAL orPRIVATE previously14150: PRIVATE ignored, procedure was declared
Error Messages 275B14300: Expected keyword begin after declarations, beforestatements14310: Improper initialization for variable <identifier>1432
iiiContentsPreface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix1. Introduction. . . . .
6 Pascal 4.0 User’s Guide1
276 Pascal 4.0 User’s GuideB15100: Cannot open #include file <filename>15110: line <number> does not exist in file <identifier>15120:
Error Messages 277B16160: Procedure/function nesting too deep16170: Can't call <identifier>, its not a pointer to aprocedure or function161
278 Pascal 4.0 User’s GuideB17100: Predecessor of <integer> is out of range17110: Value of <integer> is out of range17120: Range upper bou
Error Messages 279B18120: 8 or 9 in octal number18130: Number too large for this implementation18140: <operation> is undefined for reals18150: &
280 Pascal 4.0 User’s GuideB18420: Undefined <identifier>18430: Undefined identifier18440: Improper <identifier> identifier18450: Deleted &l
Error Messages 281B18630: Unreachable statement18640: Unrecoverable syntax error - QUIT18650: Too many syntax errors - QUIT18660: Input line too long
282 Pascal 4.0 User’s GuideB19030: Missing program statement19040: Input is used but not defined in the programstatement19050: Output is used but not
Error Messages 283B20140: Operands of <operator> must both be sets20150: Set types of operands of <operator> must be compatible20160: Inco
284 Pascal 4.0 User’s GuideB21070: Conformant array parameters in the samespecification must be the same type21080: actual parameter is not an array21
Error Messages 285B21230: Program parameter <identifier> is repeated21240: Previous declaration for formal parameter '<identifier>&apos
7Pascal Programs2This chapter cites two examples that illustrate how to compile and execute aprogram. It also explains how to use the traceback facil
286 Pascal 4.0 User’s GuideB22020: Ran out of memory (case)22030: Ran out of memory (hash)22040: Ran out of memory (TRIM)22050: Ran out of memory (def
Error Messages 287B23070: Routine Options are not standard23080: External procedures and functions are not standard23090: Separately compiled routine
288 Pascal 4.0 User’s GuideB23270: Storage Class non-standard23280: Initialization in declaration part is non-standard23290: UNIV_PTR types are non-st
Error Messages 289B24120: Case selectors cannot be <type>s24130: Duplicate otherwise clause in case statement24140: Case label type clashed with
290 Pascal 4.0 User’s GuideB24300: Improper use of the DEFINE statement24310: End matched <keyword> on line <number>24320: Inserted keywor
Error Messages 291B25150: Type clash: packed and unpacked set25160: Type clash: files not allowed in this context25170: Type clash: non-identical <
292 Pascal 4.0 User’s GuideB25320: Function type should be given only in forwarddeclaration25330: Different type declared previously for functionretur
Error Messages 293B25490: <class> types must be identical in comparisons -operator was <operator>25500: Index type clashed with set compon
294 Pascal 4.0 User’s GuideB25670: Index type for arrays cannot be real25680: Array index type is a <type>, not a range or scalaras required2569
Error Messages 295B26140: Extension to WITH statement not allowed27010: Integer overflow in constant expressionThe following are internal error messag
8 Pascal 4.0 User’s Guide2Compiling the ProgramNow compile the program with pc, the Pascal compiler, by typing at thesystem prompt:hostname% pc temp.p
296 Pascal 4.0 User’s GuideB
297IndexA–a option to pc command, 24a.out, 2,8,9,17address parameters, 169alignment of types in FORTRAN, 165and operator, 38AnswerBook, xxiiarguments,
298 Pascal 4.0 User’s Guidevar parameters, 94, 117C++ programming language, 137 to 162arguments, passing ofby reference, 139, 155by value, 150, 157arr
Index 299–config option, 245, 252, 256defined, 246undefined, 245%config directive, 247–config option to pc command, 27, 246,252conformant arraysparamete
300 Pascal 4.0 User’s Guidein type equivalence, 214out of memory, 217runtime, 217 to 220exception-handling function in mathlibraries, 240executable fil
Index 301identifier errors, 208identifiers, 33, 46, 76IEEE support functions in mathlibraries, 236%if directive, 247, 257%ifdef directive, 255, 257, 258
302 Pascal 4.0 User’s Guidematherr() exception-handlingfunction, 240Pascal header files, 233SPARC libraries, 238memory, out of, 217–misalign option to
Index 303–dalign option, 28–dn option, 28–dryrun option, 28–dy option, 28–fast option, 28-flags option, 32–fnonstd option, 29-fns option, 29-fround=r
304 Pascal 4.0 User’s Guideprocedureand function type errors, 211extern option, 86, 88external,88linelimit,25type errors, 211write,46programbreakup of
Index 305#define,27assert,25stdin,10stdout,10string errors, 206symbolerrors, 208table for dbx,61syntax errors and recovery, 205 to 207T-tc option to p
Pascal Programs 92Running the ProgramTo run the program, enter a.out at the prompt. The output of temp.p is thendisplayed:Renaming the Executable Fil
306 Pascal 4.0 User’s Guidewriting a Pascal program, 7writing scalars, errors in, 212X–xarch=a option to pc command, 49–xcache=a option to pc command,
Index 307
Copyright 1995 Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, Californie 94043-1100 U.S.A.Tous droits réservés. Ce produit ou document est
10 Pascal 4.0 User’s Guide2Now run the program by typing the name of the executable file. The outputfollows:An Interactive Pascal ProgramIn Pascal, th
Pascal Programs 112Compiling the ProgramUse the pc command to compile the program and store it in the executable filecopy. Here is the command format:
12 Pascal 4.0 User’s Guide2Using the same program, but with the < operator to redirect input, you canprint the file on the terminal:Using a File Nam
Pascal Programs 132Assuming that the file data is still in the current directory, you can compileand run the program as follows:Where Did My Program Fa
14 Pascal 4.0 User’s Guide2Using a Sample Program with Segmentation ViolationA segmentation violation occurs when your program tries to reference memo
Pascal Programs 152In this example, ErrorInHere reported the error. The ErrorInHereprocedure was called by Call1.Call2, which was in turn called by t
iv Pascal 4.0 User’s GuideCompiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Running the Program . . . . . . . . . . .
16 Pascal 4.0 User’s Guide2Try compiling SegViol.p with –g:The program prints the ASCII values of character variables.If you compile some modules with
17The Pascal Compiler3The name of the Pascal compiler is pc. If you give pc a file name as anargument, and the file name ends with .p or .pas, pc compi
18 Pascal 4.0 User’s Guide3To identify the version number given an executable or object file created by thePascal compiler, use the following command.C
The Pascal Compiler 193Figure 3-1 shows the sequence of events when you invoke pc.Figure 3-1 Organization of Pascal CompilationLanguage PreprocessorTh
20 Pascal 4.0 User’s Guide3See the man page for cpp(1) for information on its directives and otherfeatures. Appendix A, “Pascal Preprocessor,” describ
The Pascal Compiler 213Option-Passing on the Command-LineTo pass an option on the command-line, use a dash (-) followed by the optionname. In some ca
22 Pascal 4.0 User’s Guide3You set options within comments, which can be delimited by either { and } or(* and *). The first character in the comment m
The Pascal Compiler 233If no values have been pushed onto the stack, the effect of * is undefined.Figure 3-2 illustrates how options are passed in prog
24 Pascal 4.0 User’s Guide3–aThe –a option is the old style of basic block profiling for tcov. See-xprofile=tcov for information on the new style of p
The Pascal Compiler 253The –b option on the command-line turns on block-buffering with a block sizeof 1,024. You cannot turn off buffering from the c
Contents v–c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-calign . . . . . . . . . . . . . . . .
26 Pascal 4.0 User’s Guide3–cThe –c option instructs the compiler not to call the linker, ld(1). The Pascalcompiler, pc, leaves a .o or object file fo
The Pascal Compiler 273The –cond option instructs pc to compile the lines in your program that beginwith the %debug compiler directive. If you compil
28 Pascal 4.0 User’s Guide3–dalignThe –dalign option instructs the compiler to generate double load and storeinstructions wherever possible for faster
The Pascal Compiler 293Do not use this option for programs that depend on IEEE standard exceptionhandling; you can get different numerical results, pr
30 Pascal 4.0 User’s Guide3The default is -fround=nearest.The meanings are the same as those for the ieee_flags subroutine.If you compile one routine
The Pascal Compiler 313–gThe –g option instructs pc to produce additional symbol table information fordbx and debugger. With -g, the incremental link
32 Pascal 4.0 User’s Guide3Every executable file has a list of needed shared library files. When theruntime linker links the library into an executable
The Pascal Compiler 333–LThe –L option maps all keywords and identifiers to lowercase. In Pascal,uppercase and lowercase are not interchangeable in id
34 Pascal 4.0 User’s Guide3-libmieeeForces IEEE 754 style return values for math routines in exceptional cases. Insuch cases, no exception message is
The Pascal Compiler 353–nativeThe –native option causes pc to generate code for the best floating-pointhardware available on the machine you are compil
vi Pascal 4.0 User’s Guide–L. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33–l. . . . . . . . . . .
36 Pascal 4.0 User’s Guide3-notraceThe -notrace option disables runtime traceback. It is only effective whencompiling the main program.–O[level]The –
The Pascal Compiler 373–O3, -xO3Same as -O2, but optimizes the uses and definitions of external variables.Level -O3 does not trace the effects of point
38 Pascal 4.0 User’s Guide3This command causes the optimizer to try to recover if it reaches 16 megabytesof data space.This limit cannot be greater th
The Pascal Compiler 393–p and –pgThe –p and –pg options instruct the compiler to produce code that counts thenumber of times each routine is called.
40 Pascal 4.0 User’s Guide3–QoptionThe –Qoption passes an option to the program. The option value must beappropriate to that program and can begin wi
The Pascal Compiler 413-R(Solaris 1.x only) The –R option instructs pc to call the assembler, as(1). Thisoption merges the data segment of the resul
42 Pascal 4.0 User’s Guide3The compiler issues warnings at the end of the procedure where the recordvariables are defined, that is, when some of the fie
The Pascal Compiler 433Examples:The Pascal main program, r.p(record and array of records)program p;procedure qq;type compl = record re, im: integer en
44 Pascal 4.0 User’s Guide3The commands to compilerr.p and the -Rw warningsthat are issuedhostname% pc -Rw rr.pMon Feb 20 14:59:04 1995 pas/rr.p:In p
The Pascal Compiler 453The Pascal main program,with.p (with statement)program p;type C = record re, im: integer end; AC = array[1..2] of C; RC
Contents vii-R path[:dir] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41-Rw. . . . . . . . . . . . . . . . . . . . . .
46 Pascal 4.0 User’s Guide3–SThe –S option compiles the program and outputs the assembly language in thefile, sourcefile.s. For example, the following
The Pascal Compiler 473-tcThe -tc option instructs the compiler to generate pc3 stab information thatallows cross-module type checking.This option can
48 Pascal 4.0 User’s Guide3–timeThe –time option instructs the compiler to report execution performancestatistics for the various compilation passes.
The Pascal Compiler 493–U nameThe –U option removes any initial definition of the cpp(1) symbol name. Seecpp(1) for more information. You cannot use
50 Pascal 4.0 User’s Guide3a must be one of: generic, v7, v8, v8a, v8plus, v8plusa.Although this option can be used alone, it is part of the expansion
The Pascal Compiler 513v7, v8, and v8a are all binary compatible. v8plus and v8plusa are binarycompatible with each other and forward, but not backwar
52 Pascal 4.0 User’s Guide3v8 Limit the instruction set to V8 architecture.This option uses the best instruction set for good performance on the V8arc
The Pascal Compiler 533-xcache=c(Solaris 2.x only) The -xcache=c option defines the cache properties for use bythe optimizer.c must be one of the follo
54 Pascal 4.0 User’s Guide3Example: -xcache=16/32/4:1024/32/1 specifies the following:-xchip=c(Solaris 2.x only) The -xchip=c option specifies the targe
The Pascal Compiler 553-xcg89Same as -cg89.-xcg92Same as -cg92.–xF(Solaris 2.x only) The –xF option enables performance analysis of the executablefile
viii Pascal 4.0 User’s Guide-xlibmieee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56-xlibmil. . . . . . . . . . . .
56 Pascal 4.0 User’s Guide3-xildoff(Solaris 2.x only) Turns off the incremental linker and forces the use of ld. Thisoption is the default if you do
The Pascal Compiler 573-xlibmoptUses a math routine library optimized for performance. The results may beslightly different than those produced by th
58 Pascal 4.0 User’s Guide3Generates the highest level of optimization. Uses optimization algorithms thattake more compilation time or that do not hav
The Pascal Compiler 593This option causes execution frequency data to be collected and saved duringexecution, then the data can be used in subsequent
60 Pascal 4.0 User’s Guide3-xregs=r(Solaris 2.x only) The -xregs=r option specifies the usage of registers for thegenerated code.r is a comma-separated
The Pascal Compiler 613–xs(Solaris 2.x only) The -xs option disables Auto-Read for dbx in case youcannot keep the .o files around. This option passes
62 Pascal 4.0 User’s Guide3-xspace(Solaris 2.x only) The -xspace option does no optimizations that increase thecode size.Example: Do not unroll loops.
The Pascal Compiler 633very important. This is especially true when running on the newer SPARCprocessors. However, for most programs and older SPARC p
64 Pascal 4.0 User’s Guide3sun4/670 v7 old 64/32/1sun4/690 v7 old 64/32/1sselc v7 old 64/32/1ssipc v7 old 64/16/1ssipx v7 old 64/32/1sslc v8a micro 2/
The Pascal Compiler 653ss10/51 v8 super 16/32/4:1024/32/1ss10/61 v8 super 16/32/4:1024/32/1ss10/71 v8 super2 16/32/4:1024/32/1ss10/402 v8 super 16/32/
Contents ixSharing Variables Between Units. . . . . . . . . . . . . . . . . . . . . . 71Libraries . . . . . . . . . . . . . . . . . . . . . . . . . .
66 Pascal 4.0 User’s Guide3–ZThe –Z option instructs pc to insert code that initializes all local variables tozero. Standard Pascal does not allow in
67Program Construction andManagement4This chapter is an introduction to the methods generally used to construct andmanage programs using Pascal. It d
68 Pascal 4.0 User’s Guide4The actual includefile looks like this:In this example, the include file contains the entire program. In reality, aninclude
Program Construction and Management 694The body of the procedure say_hello is not defined in this program unit,but the program unit does contain a decl
70 Pascal 4.0 User’s Guide4You can also separate the compilation and linking or loading steps, as follows:hostname% pc program_unit.p -chostname% pc m
Program Construction and Management 714In a real program, header.h would probably contain many declarations andwould be included in several modules.
72 Pascal 4.0 User’s Guide4Here is a program unit that declares a variable:Here is a module unit that declares a variable with the same name:program p
Program Construction and Management 734By default, both definitions of variable x are public. Thus, when you compileand link the program and module un
74 Pascal 4.0 User’s Guide4LibrariesYou can use a module unit as a library of useful functions. The simplest wayto do so is to create a source file co
75Separate Compilation5This chapter describes how to compile Pascal programs in separate units.Chapter 4, “Program Construction and Management,” gives
Kommentare zu diesen Handbüchern