Home
HP SunSoft Pascal 4.0 User's Manual
Contents
1. Pascal 4 0 User s Guide The C main program VarRecMain c The commands to compile and execute VarRec pand VarRecMain c include lt stdio h gt struct vlr char tag union struct char chl ch2 ja_var struct char flag b_var struct int ALIGN c_var var_part extern void VarRec struct vlr int main void struct vlr x x struct vlr malloc sizeof struct vlr x gt tag a X gt var_part a_var chl a X gt var_part a_var ch2 b VarRec x printf Sc An x gt var_part a_var ch2 hostname pe c calign VarRec p hostname cc VarRec o VarRecMain c lpc hostname a out Z The C Pascal Interface 109 110 Pascal Set Type In Pascal a set type is implemented as a bit vector which is similar to a C short word array Direct access to individual elements of a set is highly machine dependent and should be avoided In Pascal bits are numbered within a byte from the most significant to least as shown in Table 6 3 Table 6 3 Set Implementation Set Bit Numbering set 3 31 30 29 28 27 26 25 24 set 2 23 22 21 20 19 18 17 16 set 1 15 14 13 12 11 10 9 8 set 0 7 6 5 4 3 2 1 0 In C a set could be described as a short word array beginning at an even address With the current set representation it does not matter what the lower bound value is The nth element in a
2. var global integer procedure proc extern hostname pe inc_prog p inc_mod p inc_prog p inc_mod p Linking hostname S a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 Separate Compilation 79 lll a Using the x1 Option The commands to compile and execute shrvar_prog pand shrvar_mod p with the x1 option 80 When you use the x1 option variables and top level procedures and functions declared in the program unit default to private Look at the difference when you compile and execute shrvar_prog p and shrvar_mod p with x1 See the source code in Sharing Public Variables on page 77 hostname S pc xl shrvar_prog p shrvar_mod p shrvar_prog p shrvar_mod p Linking hostname s a out From MAIN before PROC 1 From PROC 0 From MAIN after PROC 1 Without x1 the variable global in shrvar_mod p is treated as public here global is treated as private Thus the assignment global global 1 is not reflected in shrvar_prog p instead each file uses its own private copy of global The following sections describe five ways of sharing variables and routines across units when you compile your program with x1 Using public var Declarations The following examples uses the public attribute in the var declaration to make global public when you compile your program with x1 Pascal 4 0 User s Guide The program unit
3. Examples of single dimension array and array of character conformant arrays follow Conformant arrays are included here only because they are a relatively standard feature there are usually more efficient and simpler ways to do that The FORTRAN Pascal Interface 173 111 Co The Pascal procedure IntCA p Pascal passes the bounds by value The FORTRAN main program IntCAmain f The commands to compile and execute IntCA p and IntCAmain f The Pascal procedure ChrCA p Pascal passes the bounds by value 174 Example 1 Single Dimension Array procedure intca_ var a array lb ub integer of integer integer k integer s 0 2 data s call IntCA do k 0 2 write I1 end do stop end 0 0 0 s VAL 0 hostname pe c IntCA p hostname 77 IntCA o IntCAmain f lpfc lpc IntCAmain f MAIN hostname a out 0 1 2 Example 2 Array of Characters procedure chrca_ var a array lb ub integer of char Pascal 4 0 User s Guide Co lll The FORTRAN main program ChrCAmain f The commands to compile and execute ChrCA p and CharCAmain f character s 16 data s this is a string call ChrCA s VAL 0 SVAL 15 write A S stop end hostname pe c ChrCA p hostname 77 ChrCA o ChrCAmain f lpfc lpc ChrCAmain f MAIN hostname a out This is a string Records and Structur
4. For information on the operating environment see the READM Installation E file For instructions on how to install Pascal refer to the Installing SunSoft Developer Products SPARC Solaris manual xix Audience Organization XX 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
5. Cannot write lt fype gt s with two write widths Can t write lt identifier gt s with oct hex First write width must be integer not lt type gt Second write width must be integer not lt type gt Negative widths are not allowed Cannot write unpacked array to textfile Can t read lt type gt s from a text file Can t readln a non text file Oct hex allowed only on text files Write widths allowed only on text files Cannot write unpacked array to textfile Can t write lt type gt s to a text file Can t writeln a non text file constant identifier required Constant value cannot be evaluated at compile time Constant too large for this implementation lt identifier gt is a constant and cannot be qualified Constant string too long Constant expression is required Pascal 4 0 User s Guide Ss lll 13070 constant argument expected 13080 newline in string or char constant 13090 empty character constant 13100 too many characters in character constant 14010 Constant declarations should precede type var and routine declarations 14020 Label declarations should precede const type var and routine declarations 14030 Type declarations should precede var and routine declarations 14040 All types should be declared in one type part 14050 All constants should be declared in one const part 14060 INTERNAL ignored procedure was previously declared PUBLIC or as EXTERNAL
6. fast option to pc command 28 faster linking and initializing 61 fbe 1 assembler 40 features Pascal compiler 2 file name extensions 20 variable 12 flags option to pc command 32 floating point nonstandard 29 fnonstd option to pc command 29 fns option to pc command 29 format of error diagnostics 210 FORTRAN programming language 163 to 204 and Pascal compatible types 165 arrays by value 182 character dummy arguments 189 compatible types 164 FORTRAN calls Pascal 168 to 185 function return values 184 201 incompatibilities with Pascal 166 parameter passing 167 Pascal calls FORTRAN 185 to 202 Pascal 4 0 User s Guide interface 163 procedures and functions as parameters 202 to 204 records and structures 175 194 sharing declarations 88 strings by value 182 value parameters 181 197 var parameters 168 186 to 197 fround r option to pc command 29 ftrap t option to pc command 30 function extern option 86 88 external 88 return values with C 115 130 return values with FORTRAN 184 201 type errors 211 G G option to pc command 30 g option to pc command 31 global variables C and Pascal 133 C and Pascal 161 goto statement compiler semantic error 216 H H option to pc command 31 49 handles XView 226 header files for XView 224 in a program 70 math libraries 233 help option to pc command 32 hname option to pc command 31 I I option to pc comm
7. y void StruChr struct TVarLenStr v strncpy v gt a strvar 6 v gt nbytes 6 124 Pascal 4 0 User s Guide The Pascal main program StruChrMain p The commands to compile and execute St ruChr c and StruChrMain p program StruChrMain output type TVarLenStr record nbytes integer a array 0 25 of char end var vis TVarLenStr i integer procedure StruChr var vls TVarLenStr begin StruChr vls write string for i 0 to vls nbytes 1 do write vls a i writeln writeln length vls nbytes end StruChrMain external c hostname cc c StruChr c hostname a out hostname pe calign StruChr o StruChrMain p string strvar length 6 Variant Records C equivalents of variant records can sometimes be constructed although there is some variation with the architecture and sometimes you have to adjust the alignment The C Pascal Interface 125 lll O The C function VarRec c 126 Following are some examples struct vir char tag union struct char chl ch2 a_var struct char flag b_var struct int ALIGN e yar var_part y void VarRec struct vlr x if x gt var_part a_var chl a X gt var_part a_var ch2 Z Pascal 4 0 User s Guide o lll The Pascal main program VarRecMain p The commands to compile and execute VarRec
8. 17170 Tag type is out of range 17180 Base out of range 2 36 18020 in a comment 18030 in a comment 18040 Comment does not terminate QUIT o 18050 Illegal character use th xl option to process compiler directives 18060 Illegal character 18070 unexpected EOF 18080 Point of error 18090 Parsing resumes 18100 Parse stack overflow 18110 Expression passed to UNIV formal lt identifier gt was converted to lt type gt of size lt number gt bytes 278 Pascal 4 0 User s Guide Ss lll 18120 8 or 9 in octal number 18130 Number too large for this implementation 18140 lt operation gt is undefined for reals 18150 lt identifier gt cannot have mor lements in z lt integer gt than in a lt integer gt 18160 lt identifier gt is an unimplemented extension 18180 Initializer must be a string 18190 Initialization string lt string gt is too long 18200 Expected options not lt identifier gt 18210 Unknown option ignored lt identifier gt 18220 Duplicate options specification lt identifier gt 18230 Unimplemented option ignored lt identifier gt 18240 lt identifier gt undefined on line lt number gt 18250 lt identifier gt improperly used on line lt number gt 18260 lt identifier gt is neither used nor set 18270 lt identifier gt is never used 18280 lt identifier gt is used but never set 18
9. This following Pascal program demonstrates how to abort on division by zero program TestIEEEHandler output include lt math_p h gt procedure DivisionHandler sig integer sip univ_ptr uap univ_ptr begin writeln Bad data division by zero end DivisionHandler var FpAction FpException string Zero integer 0 begin FpAction set FpException division writeln i _handler FpAction FpException addr DivisionHandler writeln 1 0 1 Zero writeln i _handler FpAction FpException SIGFPE_DEFAULT writeln 1 0 1 Zero end ieee_flags is the recommended interface to Query or set rounding direction mode Query or set rounding precision mode e Examine clear or set accrued exception flags 242 Pascal 4 0 User s Guide An The syntax of this function is described in the ieee_flags 3M man page If an exception is raised at any time during program execution then its flag is set unless it is explicitly cleared Clearing accrued exceptions is done by a call as shown in the following Pascal program program TestlEE EFlags output var Zero integer begin writeln sqr writeln exp end writeln 1 Zero writeln exp 709 8 708 5 include math_p h FlAction FlMode FlIn string FlOut string_ pointer 0 1 Invali
10. end StruChr The C Pascal Interface 105 lll O The C main program include lt stdio h gt StruChrMain c include lt string h gt struct TVarLenStr int NBytes char a 25 y extern void StruChr struct TVarLenStr int main void struct TVarLenStr vls char S25 Landis vls NBytes 0 StruChr amp vl1ls strncpy s25 vls a vls NBytes printf s25 Ss An s25 printf strlen s25 d An strlen s25 The commands to compile and hostname pe c StruChr p execute StruChr p and hostname cc StruChr o StruChrMain c lpc StruChrMain c hostname a out s25 St Petersburg strlen s25 13 The record in the example above has by default the same size and alignment as the equivalent C record Some records though are laid out differently unless you use the calign option 106 Pascal 4 0 User s Guide The Pascal routine DayWeather p The C main program DayWeatherMain c Consider this example type TDayWeather record TDay array 0 8 of char TWeather array 0 20 of char end TDayWeatherArray array 0 1 of TDayWeather procedure DayWeather var W TDayWeatherArray var WeatherSize integer begin W 1 TDay Sunday chr 0 W 1 TWeather Sunny chr 0 WeatherSize 5 end StruChr include lt stdio h gt include lt string h gt struct TDayRec char TDay 9 ch
11. no inexact The default is ftrap none This option sets the IEEE 754 trapping modes that are established at program initialization Processing is left to right The common exceptions by definition are invalid division by zero and overflow Example ftrap all no inexact means set all traps except inexact The meanings are the same as for the ieee_flags function except that all turns on all the trapping modes S none the default turns off all trapping modes A nos prefix turns off that specific trapping mode If you compile one routine with ft rap t compile all routines of the program with the same ft rap t option otherwise unexpected results may occur Solaris 2 x only The G option builds a shared library All object files specified with this command option should have been compiled with either the pic or the PIC option Pascal 4 0 User s Guide Oy lll hname The g option instructs pc to produce additional symbol table information for dbx and debugger With g the incremental linker ilaq is called instead of ld You can compile using both the g and 0 options However there are some side effects e The next and step commands do not work but the cont command does If you have makefiles that rely on g overriding O you must revise those files e If you have makefiles that check for a warning message that g overrides 0 you must revise those make files Note Spe
12. 100 printf Hello C An Pascal 4 0 User s Guide The commands to compile and execute 1IO pand IOMain c hostnames pe c IO p hostnames cc IO o IOMain c lpc hostname a out Hello Pascal and St Petersburg Hello C Procedure Calls Pascal C This section parallels the section Procedure Calls C Pascal on page 93 Earlier comments and restrictions also apply here Variable Parameters Pascal passes all variable parameters by reference which C can do too Simple Types Simple types pass in a straightforward manner as follows The C function SimRef c void SimRef char eC char Ri char mo short si int 1 float sr double ey t 1 f 0 ke 1z xsi 9 i 9 sr 9 9 r 9 9 The C Pascal Interface 117 lll O The Pascal main program program SimRefMain output SimRefMain p var t boolean Cs char si integerl6 i integer sr shortreal r real procedure SimRef var t f boolean var c char var si integerl6 var i integer var sr shortreal var Y real external c begin SimRef t f c si i Sr Yr writeln t f 6 c 2 si 2 i 2 sr 4 1 4 1 end SimRefMain The commands to compile and hostname cc c SimRef c execute SimRef c and hostname pe SimRef o SimRefMain p SimRefMain p hostname a out true false z 9 9 9 9 9 9 Strings
13. 9 To make the assignment statement work you must declare a type and use it to declare the variables as follows type r record a integer b char end var RY Ffi y Y Alternatively you could use the declaration x y record a integer b char end The assignment statement then works Unreachable Statements Pascal flags unreachable statements Such statements usually correspond to errors in the program logic as shown in the following example The Pascal program program unreached_example output unreached p label 1 begin goto 1 writeln Unreachable ds writeln Reached this end unreached_example Error Diagnostics 215 lll Ko This error message is generated when you compile unreached p hostname pe unreached p Tue Feb 14 14 21 03 1995 unreached p w 18630 line 8 Unreachable statement A statement is considered to be reachable if there is a potential path of control even if it cannot be taken Thus no diagnostic is produced for the statement if false then writeln Impossible The goto Statement Pascal detects and produces an error message about goto statements that transfer control into structured statements for example for and while It does not allow such jumps nor does it allow branching from the then part of an if statement into the else part Such checks are made only within the body
14. NFS OpenWindows DeskSet ToolTalk SunView XView X11 NeWS AnswerBook and Magnify Help are trademarks or registered 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 product names mentioned herein are the trademarks of their respective owners All SPARC trademarks including the SCD Compliant Logo are trademarks or registered trademarks of SPARC International Inc in the United States and may be protected as trademarks in other countries SPARCcenter SPARCcluster SPARCompiler SPARCdesign SPARC811 SPARCengine SPARCprinter SPARCserver SPARCstation SPARCstorage SPARCworks microSPARC microSPARC II SPARCware and UltraSPARC are licensed exclusively to Sun Microsystems Inc Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems Inc 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
15. Sinclude bird h begin Sifdef not bird1 Sthen Svar birdl Selseifdef not bird2 then Svar bird2 Sendif Sif birdl then writeln Bird one is a a Selseif bird2 Sthen writeln Bird two is a b Sendif end ifdef_example Pascal Preprocessor 253 A The include file bird h The output when you enable birdl with the config option The output when you enable bird2 with the config option 254 var a array 1 7 of char penguin b array 1 6 of char toucan Svar birdl hostname pe x1 config birdl ifdef p hostnames a out Bird two is a penguin hostname pe x1 config bird2 ifdef p hostname S a out Bird two is a toucan The Senable Directive The enable directive sets a conditional variable to true Syntax enable varl varN Comments A defined conditional variable is enable true when it appears in either the enable directive or in the config option Conditional variables are false by default Pascal 4 0 User s Guide os lll The Pascal program enable p This example sets the conditional variable t wo to true which is equivalent to setting the config option to two onthe command line The commands to compile and output enable p Example program enable_example output This program demonstrates the use of the Senable compiler directive var a integer b integer Svar one two S
16. Sunday end The C main program include lt stdio h gt DaysOfWeekMain c extern void DaysOfWeek char 7 9 int main void char Year 52 7 9 DaysOfWeek Year printf Day s An Year 1 1 The commands to compile and hostname pe c DaysOfWeek p execute DaysOfWeek p and hostname cc DaysOfWeek o DaysOfWeekMain c lpc DaysOfWeekMain c without hostname a out calign Day The commands to compile and hostname pe c calign DaysOfWeek p execute DaysOfWeek p and hostname cc DaysOfWeek o DaysOfWeekMain c lpc DaysOfWeekMain c with hostname a out calign day Sunday The C Pascal Interface 99 lll O The Pascal procedure UniVec p which defines a 10 element array The C main program UniVecMain c which passes a 3 element array to the Pascal procedure written to do a 10 element array 100 The univ Arrays You can pass any size array to a Pascal procedure expecting a univ array although there is no special gain in doing so because there is no type or size checking for separate compilations However if you want to use an existing Pascal procedure that has a univ array you can do so All univ arrays that are in out in out or var parameters pass by reference type TVec array 0 9 of integer procedure UniVec var V univ TVec in Last integer var Sum integer var i integer begin Sum 0 for i 0 to Last do Sum Sum V i end UniVec i
17. You can construct FORTRAN equivalents of variant records There is some variation with architecture and sometimes you need to adjust the alignment The FORTRAN Pascal Interface 195 111 Co The FORTRAN subroutine VarRec f The variable ALIGN is integer 2 and is needed to match the Pascal variant record layout 196 Chapter 6 The C Pascal Interface has an example that matches the following example S S S S subroutin ture a_var CrUuc end s CEUC end s CIUC end s truc Cure cure VarRec VRec character chl ch2 tructure b_var character flag tructure c_var integer 2 ALIGN tructure ture var_part union map record a_var a_rec end map map record b_var b_rec end map map record c_var c_rec end map end union end structure structure vrnt character tag record var_part var_rec end structure record vrnt VRec if VRec var_rec a_rec chl eq a VRec var_rec a_rec ch2 Z return end Pascal 4 0 User s Guide Co lll The Pascal main program program VarRecmain VarRecmain p type vr record case tag char of rat chi ene char J b flag boolean K ALIGN integer end var Rec vr procedure varrec var d vr external fortran begin Rec tag a Rec chl a Rec ch2 b varrec Rec writeln Rec ch2 end VarRecmain T
18. compile your program without the x1 option Sharing Public Variables If you declare a variable in two or more separate units and the variable is public in both places that variable is shared between units Variables are public by default unless you compile with the x1 option in which case variables are private by default In this example the variable global is public by default and thus shared between the program and the module program shrvar_prog var global integer procedure proc external begin program body global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end shrvar_prog module shrvar_mod var global integer procedure proc begin writeln From PROC global global global 1 end proc Separate Compilation Z7 lll a The commands to compile and execute shrvar_prog pand shrvar_mod p 78 hostname pe shrvar_prog p shrvar_mod p shrvar_prog p shrvar_mod p Linking hostnames a out From MAIN before PROC 1 From PROC lt T From MAIN after PROC 2 Using extern Option to Share Routines If a program or module calls a procedure not defined in that unit you must declare it with either the extern or external routine option For instance in the previous example the procedure proc is defined in shrvar_mod p but used in shrvar_prog p Thus it is declared as ext
19. float double E int main void char Er Ey CF int dis short S float es double d SamRef t f c i s r d printf 080 080 c d d 3 1f 3 1f An t Es Gy Ey Sp Ly d hostnames pe c SamRef p hostname CC SimRef o SamRefMain cc lpc hostnames a out 00000001 00000000 z 9 9 9 9 9 9 Simple Types with the x1 Option With the x1 option the Pascal real must be paired with a C float the Pascal integer must be paired with a C short int The C 4 Pascal Interface 141 lll N The Pascal procedure StrRef p 142 Strings of Characters The C counterpart to the Pascal alfa and string types are arrays The C counterpart to the Pascal varying type is a structure Here is an example type TVarStr varying 25 of char procedure StrRef var a alfa var s string Var v TVarStr begin a abcdefghi chr 0 s abcdefghijklmnopqrstuvwxyz chr 0 v varstr chr 0 end Pascal 4 0 User s Guide The C main program StrRefMain cc The commands to compile and execute StrRef pand StrRefMain cc include lt stdio h gt include lt string h gt struct TVarLenStr int NBytes char a 25 extern C void StrRef char char Er TVarLenStr int main void struct TVarLenStr vls char s10 10 s80 80 s25 25 vls NBytes 0 StrRef s10 s80 vls strncpy s25 vls a v
20. it s lt class gt not a procedure 16190 Procedure lt identifier gt found where expression required 16200 Illegal procedure call expecting value 16210 Non pascal routine lt identifier gt will fail if called indirectly from pascal 16220 Passing nested routine lt identifier gt to non pascal routine lt identifier gt 16230 Can t call lt identifier gt its not a pointer to a procedure or function 17010 Case label out of range 17020 Real constant out of range for this implementation 17030 Short real out of range for this implementation 17040 Short real lt number gt out of range for this implementation 17050 Implementation restriction sets must be indexed by 16 bit quantities 17060 Subscript of lt identifier gt is out of range 17070 Subscript value of lt number gt is out of range 17080 subrange value or array subscript lt integer gt is out of range 17090 Successor of lt integer gt is out of range Error Messages 277 lll Se 17100 Predecessor of lt integer gt is out of range 17110 Value of lt integer gt is out of range 17120 Range upper bound of lt integer gt out of set bounds 17130 Range lower bound of lt integer gt out of set bounds 17140 Value of lt integer gt out of set bounds 17150 value of lt integer gt initial assign to for loop variable is out of range 17160 Value of lt integer gt terminal assign to for loop variable is out of range
21. s 9 sr 9 9 end simvar_ logical 1 Ey character c integer 4 i double precision d integer 2 si real sr call SimVar ty E Cr ity ds Sl SE write L2 L2 A2 12 F4 1 12 F4 1 amp tv Es E Ep d Sipsi stop end hostname pe c SimVar p hostnames 77 SimVar o SimVarmain f lpfc lpc SimVarmain f MAIN hostnames a out TF z 99 9 9 9 9 The FORTRAN Pascal Interface 169 lll Co The Pascal procedure StrVar p The FORTRAN main program StrVarmain f 170 Simple Types with the x1 Option When you pass the x1 option the Pascal data type real must be paired with a FORTRAN data type real the Pascal data type integer must be paired with a FORTRAN data type integer 2 Strings of Characters The FORTRAN counterpart to the Pascal alfa and string types is a character string and the FORTRAN counterpart to the Pascal varying is a structure By default FORTRAN passes all by reference type varstr varying 25 of char procedure strvar_ var a alfa var s var V Varstr string begin a abcdefghij s abcdefghijklmnopqrtstuvwxyz v oyvay strvar_ end structure VarLenStr integer nbytes character a 25 end structure record VarLenStr vls character s10 10 s80 80 s25 25 vis nbytes 0 Call StrVar s10 s80 vis s25 1 5 vls a l vls nbytes write 1 s10 s80 s25 1 format sl0 A a
22. An t25 struct TDayRec dr 2 int NBytes char s25 251 char 25 25 3 NBytes 0 DayWeather dr NBytes strncpy s25 dr 1 TDay 6 printf day Ss An s25 strncpy t25 dr 1 TWeather NBytes The C Pascal Interface 149 lll N When you compile the Pascal hostname routine without the calign option the program does not work correctly pc c DayWeather p hostnames CC DayWeather o DayWeatherMain cc lpc hostname a out day weather Sun Compile with the calign hostname pe calign c DayWeather p option The program now hostnames CC DayWeather o DayWeatherMain cc lpc works correctly hostname a out day Sunday weather Sunny Arguments Passed by Value C arguments can be passed by value In this section we describe how they work with Pascal 150 Pascal 4 0 User s Guide N lll Simple Types without the x1 Option Without the x1 option simple types match as in the following example The Pascal procedure procedure SimVal SimVal p t f boolean as char si integerl6 i integer sr shortreal r real var Reply integer begin Reply 0 if t then Reply Reply 1 if not f then Reply Reply 8 if c z then Reply Reply 64 if si 9 then Reply Reply 512 if i 9 then Reply Reply 4096 if sr shortreal 9 9 then Reply Reply 32768 if r 9 9 then Reply Repl
23. Compiling with Libraries sci niknl ia ta ededeatetitens 224 Header Ple sas a eee cee 224 Attribute Lists irritar 225 Handles ccoo ebrio 226 Data Wy POS aa AA A eee AA O 226 Coding Fragments 0 20 recorra di te es 227 Conversion of C to Pascal s ccss 00 ach eaa cane ener nanan ees 227 Pascal 4 0 User s Guide PU EXIM MO gitar eneeeesheheckugiie EE in 227 Sample Translation of an XView Function to Pascal 229 Sample POsraitne ew e n 230 Menu Demo Program a e ees 231 11 Math Libraries lt lt sE 233 Contents of the Math Libraries ooooocooommm o cm 234 e AMM 235 IEEE Support Functions aaau assas nsere rneer rrr 236 ieee f nctions J ecese eon ede eee cack E E aes aoe ae 237 TOSS VALUES scarab bk ii mentee ees 237 LEGG TEtrospeCtive astaaai vs Lata lada 238 SPARG Libraries irradia de 238 Arithmetic EXCOPONS cia a AAA 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 Figure 3 2 Figure 10 1 Organization of Pascal Compilati0N oooooomoo Options in Program Text 6 A Sample Class Hierarchy nannu nanana nrnna XV xvi Pascal 4 0 User s Guide Tables Table 3 1 Table 3 2 Table 3 3 Table 3 4 Table 3 5 Table 3 6 Table 3 7 Table 3 8 Table 3 9 Table 6 1 Table 6 2 Table 6 3 Table 8 1
24. Does not queue request if no license is available e 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 Pascal 4 0 User s Guide Pascal Programs Z This chapter cites two examples that illustrate how to compile and execute a program It also explains how to use the traceback facility to find out why a program fails The sections are A Simple Pascal Program page 7 An Interactive Pascal Program page 10 Where Did My Program Fail page 13 Building a program with SPARCompiler Pascal requires three steps 1 Writing a program in Pascal using an editor and saving it in a file with a p or pas suffix 2 Compiling the p or pas file using the pc command 3 Executing the program by typing the name of the executable file at the system prompt A Simple Pascal Program The following is a simple Pascal program that converts temperatures from Fahrenheit to Celsius Use an editor to type the code on your system and save it in a file called temp p program temperature output Program to convert temperatures from Fahrenheit to Celsius const MIN 32 MAX 50 CONVERT 5 9 var fahren integer celsius real begin
25. Samp amp i amp d printf double SILE NoT Ly 3d 3 hostname hostname hostname 9 9 9 pc c Samp p a out cc Samp o SampMain c Variable Parameters Pascal passes all variable parameters by reference which C can do too 94 Pascal 4 0 User s Guide Simple Types without x1 Without x1 simple types match as in the following example The Pascal procedure procedure SimVar SimVar p var t f boolean var c char var si integerl6 var i integer var sr shortreal var r real begin t true f false f aks si 9 i 9 sr 9 93 r 9 9 end SimVar The C main program SimVarMain c include lt stdio h gt extern void SimVar char char char short int float double int main void SimVar amp t char tm Er short si int i float sr double E amp f C printf 080 080 c d d 3 1f 3 1f n t E ty The C Pascal Interface lll O The commands to compile and execute SimVar p and SimVarMain c The Pascal procedure StrVar p 96 hostname pe c SimVar p hostname S cc SimVar o SimVarMain c hostname a out 00000001 00000000 z 9 9 9 9 9 9 Simple Types with x1 With the x1 option the Pascal real must be paired with a C float and the Pascal integer must be paired with aC short int Strings of Characters The C counterpart to the Pa
26. but the program unit does contain a declaration of the interface to the procedure The keyword extern declares that say_hello is declared in a module unit Module unit This unit can begin with an optional module header followed by a set of compilable declarations and definitions Modules that call externally defined routines must have declarations for those routines Here is an example module module_unit procedure say_hello begin writeln Hello world end Every program must have one and only one program unit a program can have any number of module units Any unit can call procedures declared in any other unit each unit must have external declarations for every procedure it uses that is not defined in that unit A module unit can also be used as a library that is as a collection of useful routines that is shared among a number of programs Compiling with Units Consider the units given in the previous section Using Program Units and Module Units You can compile and link these units on a single line by executing the following command which then produces the executable a out hostname pe program_unit p module _unit p 1 A statement that shows the interface of a routine is called a declaration because it declares the name and parameters of the routine The set of statements that shows the entire routine including the body is called the definition of the routine There can be only one def
27. hello To compile xview p and link in the necessary libraries use the following command line Replace local_library_path with the path for the Pascal XView libraries on your system hostname pe Ilocal_library_path xview p L OPENWINHOME lib lpxview lxview lolgx 1X11 Now run the executable file hostname a out Soon after you run the executable file the window opens as a single frame with the string Hello World in the frame header Pascal 4 0 User s Guide 10 Menu Demo Program Here is a more complicated program menu_demo p that makes a window and a panel with a menu button The choices displayed are Option 1 Option2 and Option 3 program MenuDemo output include stddefs_p h include attrgetset_p h var base_frame Frame base_panel Panel button Panel_button_item menu Menu frame_label string button_label string optionl Cstringp option2 Cstringp option3 Cstringp procedure menu_proc menu_ Menu menu_item Menu_item var menu_string Cstringp begin menu_string get_MENU_STRING menu_item set_FRAME_RIGHT_FOOTER base_frame menu_string end begin frame_label FRAME LABEL button_label BUTTON LABEL new optionl option1 OPTION 1 new option2 option2 OPTION 2 new option3 option3 OPTION 3 xv_init 0 The XView Toolkit 231 10 base_frame xv_
28. lt type gt 10500 chr s argument must be an integer not lt type gt 10510 Argument to eoln must be a text file not lt type gt 10520 Argument to eof must be file not lt type gt 10530 Transfer functions take only one argument 10540 Arguments to lt function gt must be variables not expressions 10550 Read requires an argument 10560 Write requires an argument 10570 Message requires an argument 10580 null takes no arguments 10590 lt function gt expects one argument 10600 Argument to lt function gt must be a file not lt type gt 10610 lt function gt expects one or two arguments 10620 First argument to lt function gt must be a file not lt type gt 10630 Second argument to lt function gt must be a string not lt type gt 10640 lt function gt expects at least one argument 10650 First argument to lt function gt must be a pointer not lt type gt Pascal 4 0 User s Guide B 10660 Second and successive arguments to lt function gt must be constants 10670 Argument to lt function gt must be a alfa not lt type gt 10680 halt takes no arguments 10690 stlimit requires one argument 10700 stlimit s argument must be an integer not lt type gt 10710 remove expects one argument 10720 remove s argument must be a string not lt type gt 10730 linelimit expects two arguments 10740 linelimit s second argument must be an integer not lt type gt 10750 linelim
29. malformed statement at the point of assignment hostname S pe synerr2 p on Feb 13 11 02 04 1995 synerr2 p 3 integer a 10 18480 R Inserted E 18490 Expected identifier 6 read b E 18420 fi Undefined variable 7 for 1 to 10 do E 18420 Undefined variable 8 alc b c E 18420 A Undefined procedure E 15010 line 1 File output listed in program statement but not declared In program synerr2_example E 18240 a undefined on line 8 E 18240 b undefined on lines 6 8 E 18240 c undefined on lines 7 8 Expected and Unexpected End of file The Pascal program mism p If pc finds a complete program but there is more noncomment text in the input file then it indicates that an end of file is expected This situation may occur after a bracketing error or if too many ends are present in the input The message may appear after the recovery says that it Expected because a period is the symbol that terminates a program If severe errors in the input prohibit further processing pc may produce a diagnostic message followed by QUIT Examples include unterminated comments and lines longer than 1 024 characters program mismatch_example output begin writeln The next lin writeln is the last line in the file Error Diagnostics 209 lll O When you compile mi sm p the end of file is reached before an end delimiter hostname pc mism p
30. nocx option 35 nolib option 35 nolibmil option 35 noqueue option 35 notrace option 36 0 option 36 o option 9 38 P option 36 38 p option 39 pg option 39 PIC option 39 pic option 39 Qoption 40 qp option 40 Opath option 40 Oproduce option 40 Index R option 41 Rpath option 41 Rw option 41 S option 46 s option 46 s0 and s1 options 49 sb option 46 sbfast option 46 tc option 47 temp option 47 time option 48 U option 49 V option 17 v option 49 V0 and V1 options 49 w option 49 xarch 4 option 49 xcache c option 53 xchip c option 54 xF option 55 xildoff option 56 xildon option 56 x1 option 56 245 xlibmopt option 57 xlicinfo option 57 xMerge option 57 xnolibmopt option 57 xregs r option 60 xs option 61 xsafe mem option 61 xspace option 62 xtarget t option 62 Z option 66 ztext option 66 pco 18 40 pc3 18 40 pg option to pc command 39 PIC option to pc command 39 pic option to pc command 39 pointer range checking 31 preprocessor 32 cpp 1 27 40 cppas 27 40 private variable 73 80 303 304 procedure and function type errors 211 extern option 86 88 external 88 linelimit 25 type errors 211 write 46 program breakup of a 67 logic errors 215 source files 75 unit 68 programming object oriented 222 procedure oriented 222 public variable 73 80 Q Qoption to p
31. real begin y i gz AI end AddOne begin a 8 0 b 0 0 passproc a b AddOne writeln a 4 1 b 4 1 end PassProcmain hostname S 77 c PassProc f PassProc f passproc hostnames pc PassProc o PassProcmain p lpfc 1F77 hostname S a out 8 0190 If the procedure is not a top level procedure then you do not deal with how to pass it because that requires allowing for the static link A procedure or function passed as an argument is associated with a static link to its lexical parent s activation record When an outer block procedure or function is passed as an argument Pascal passes a null pointer in the position normally occupied by the static link of the passed routine So that procedures and functions can be passed to other languages as arguments the static links for all procedure or function arguments are placed after the end of the conformant array bounds pairs if any The FORTRAN Pascal Interface 203 lll Co Routines in other languages can be passed to Pascal a dummy argument must be passed in the position normally occupied by the static link of the passed routine If the passed routine is not a Pascal routine the argument is used only as a placeholder 204 Pascal 4 0 User s Guide Error Diagnostics a This chapter discusses the errors you may come across while writing software programs with Pascal It contains the following sections Compiler Sy
32. 14070 lt function gt has already been declared forward 14080 Unknown language lt identifier gt in EXTERN procedure declaration ignored 14090 Unresolved forward declaration of lt function gt 14100 lt identifier gt DEFINED but not declared 14110 label lt identifier gt was declared but not defined 14120 PUBLIC procedures must be declared at outer block level 14130 PRIVATE ignored procedure was declared DEFINED previously Error Messages 273 274 14140 PRIVAT 14150 PUBLIC ignored procedure was declared INTERNAL or E previously PRIVATE ignored procedure was declared PUBLIC or as EXTERNAL previously ock in which it is used 14160 For statement variable lt identifier gt must be declared in All labels should be declared in one label part Expected identifier VARYING in declaration Variable declarations should precede routine All variables should be declared in one var part public vars must be declared Declarations may not Declarations may not Declarations may not was declared be both be both be both at outer block level STATIC and PUBLIC DEFINE and PRIVATI El EXTERN and PRIVAT GI in a DEFINE cannot be STATIC was declared in aD EFINE cannot be PRIVAT lt identifier gt used
33. 40 v8 super 16 32 4 ss10 41 v8 super 16 32 4 1024 32 1 ss10 50 v8 super 16 32 4 Pascal 4 0 User s Guide xtarget xarch xchip xcache ss10 51 v8 super 16 32 4 1024 32 1 ss10 61 v8 super 16 32 4 1024 32 1 ss10 71 v8 super2 16 32 4 1024 32 1 ss10 402 v8 super 16 32 4 ss10 412 v8 super 16 32 4 1024 32 1 ss10 512 v8 super 16 32 4 1024 32 1 ss10 514 v8 super 16 32 4 1024 32 1 ss10 612 v8 super 16 32 4 1024 32 1 ss10 712 v8 super2 16 32 4 1024 32 1 ss20 hs11 v8 hyper 256 64 1 ss20 hs12 v8 hyper 256 64 1 ss20 hs14 v8 hyper 256 64 1 ss20 hs21 v8 hyper 256 64 1 ss20 hs22 v8 hyper 256 64 1 ss20 51 v8 super 16 32 4 1024 32 1 ss20 61 v8 super 16 32 4 1024 32 1 ss20 71 v8 super2 16 32 4 1024 32 1 ss20 91 v8 super2 16 32 4 1024 32 1 ss20 502 v8 super 16 32 4 ss10 512 v8 super 16 32 4 1024 32 1 ss20 514 v8 super 16 32 4 1024 32 1 ss20 612 v8 super 16 32 4 1024 32 1 ss20 712 v8 super 16 32 4 1024 32 1 ss20 912 v8 super 16 32 4 1024 32 1 ss600 41 v8 super 16 32 4 1024 32 1 ss600 51 v8 super 16 32 4 1024 32 1 ss600 61 v8 super 16 32 4 1024 32 1 ss600 120 v7 old 64 32 1 The Pascal Compiler xtarget xarch xchip xcache ss600 140 v7 old 64 32 1 ss600 412 v8 super 16 32 4 1024 32 1 ss600 v8 super 16 32 4 1024 32 1 ss600 v8 super 16 32 4 1024 32 1 ss600 v8 super 16 32 4 1024 32 1 ss1000 v8 super 16 32 4 1024 32 1 sc2000 v8 super 16 32 4 1024 64 1 cs6400 v8 super 16 32 4 2048 64
34. E 26020 Malformed declaration 15130 s Unexpected end of fil QUIT Compiler Semantic Errors The following sections explain the typical formats and terminology used in Pascal error messages Format of the Error Diagnostics In the example program above the error diagnostics from the Pascal compiler include the line number in the text of the program as well as the text of the error message While this number is most often the line where the error occurred it can refer to the line number containing a bracketing keyword like end or until If so the diagnostic may refer to the previous statement This diagnostic occurs because of the method the compiler uses for sampling line numbers The absence of a trailing semicolon in the previous statement causes the line number corresponding to the end or until to become associated with the statement As Pascal is a free format language the line number associations can only be approximate and may seem arbitrary in some cases Incompatible Types 210 Since Pascal is a strongly typed language many type errors can occur which are called type clashes by the compiler The Pascal compiler distinguishes among the following type classes in its diagnostics array integer scalar boolean pointer string char real varying file record Pascal 4 0 User s Guide 9 Thus if you try to assign an integer value to a char variable you receive a diagnostic as fol
35. G 49 Vyand Ml e a a E EE E E 49 SV e N O e EE E E E 49 A AEE S 49 Kei tise tc A he oh eee E eae os 49 SHEL CDE ee tied fee es Be ee oo wee ween alas Os 49 TEC ACNE SO 1 cuca cc weewe A eee ewn da a 53 ECHEN ads 54 ZKO Ioer ea tad ios o 55 ACID ici ren 55 PEE vetar rre 55 E Ba st EA 56 SHUT OM OPE OO POr A Dla tee an aan EE 56 A ee eee eee ey See eee NNR EREA 56 Contents vii VAMO A aa 56 SUMO AAA poe Seas sents td foe ge es a celia res eee 0 56 SX IADMOD E eee neie eds as 57 p CALE OS as a 57 MSIE Gittins e 555 is 57 XN li De etd ee eho be bee pe eee eee hee ewe 57 2NO LIDMOPE soi ee ee bee eee dee eee ee oes 57 SEDO better a odessa eae ie thie oa le Pe 57 SZPO hhc hhc pS ane E EA NE R ee ey 58 SSP OLA A dara wee Ee ORR EE RERE ONS 58 e cosy os etek aia ve Ve aR Ree ENE ths 60 TK Sadie wie died te A ate Wasa are Be eee als eer 61 ISA fE MEM 3 civid ee Bawa Nea dees CEE E SERRE S ees 61 o iva Wild dhae 4 eee oe Seer ie bas ees 61 ESE UE A oboe eee de Posse eee es 61 ESPACIAL Mee ania oe 62 HX Car e a i cea cen et eee ee A ein 62 ee bee ab eats ahead Loe ee eee 66 AOAC Res he alae ia Pe e 66 4 Program Construction and Management 67 VIS o4 0222800 0646 6s rekura tti ii tos oie see eee eens 67 Using Program Units and Module Units 68 Compiling with Units ucerccreniaiaias Dolar ale 69 Using Units and Header Files eses sae 70 viii Pascal 4 0 User s Guide Sharing Variables Bet
36. Lo eorr een ee GEER ei ieee ener Ree es 2 Pascal PrograMS lt lt lt c prrrrrirrs ONS Cee eee eee ee N N a a FP WO WwW 0 W NY N NY KY spa A Simple Pascal Programs ico od iii Compiling the Program 45304 e0eeirrady en Running the Program rro ei Renaming the Executable File o o oo o o An Interactive Pascal Program sa bee cee ties Compiling the Program 243 2324 402r0 eseuw bude daccea Running the Program sirio Redirecting T O iicicncenseeruye Cian aia Using Pascal Tkacebatl a nc Using a Sample Program with Segmentation Violation 3 The Pascal Compilet s iii 2iisscsctunsaw sarees a AR pc Version Number 0 000 c cece ee eee eens Compile and Link Sequences cnet vie ive reee head ee ensues Language Preprocessor nu ssieveiws sae ewee sees ee eee ees File Name Extensions Accepted By pc eee eee Option Passing on the Command Line Option Passing in the Program Text ooooo oooocmoo cm OPUS brota e e EE OEN Pascal 4 0 User s Guide Ca Giants see ce ees ke epee wha EERE EM em eae a 26 EO RARA E 26 AE ri a 16 ome hee 26 CONG adora ica e ise 26 A bud E Ee ee Pate eed EEE 27 SDA SAC fxn ns eee eee O teh eee on ees 27 dali pesares hie daa de mee eels bs 28 SO isis wa ee ite eee eas PRN as chars E ide ase ede Saunas aoe RS 28 PCY TOMA ap RO 28 SOV Lie iad aoe es RAS Cee ee a 28 SHA Stok ate as Hebb Soa ea oe ie RE Sella 28 TEO
37. SO aee E eae a AA 29 HE AAA tas AA 29 PELOUDO aria Os 29 EPA san 30 e PR PAPAS o ee ee ee ee ee ee ee ee eee ee ee 30 aS ee ee er ee ee ae ee ew ee E eee er 31 iria he kk ba paa eds 31 NAME 2 oh tebe de EE ee toe bbe eee ee 31 h l p Or f 14GS merci so rete stud a des 32 ST PULNOING e eee uum Oe 32 AMO A Mant tienes Pade Sue cio 2 32 KGSPtMDs hn wn eo A Ae 6 ore we Reale be ann ee am aie oes 32 Contents v SS A ee ee ee ee ee ee ee eee ee 33 A AAA 33 HEM a da 34 lA a rr e ise 34 3 AA woe bey eee ere eek kiu ea iee 34 SMS AU Lgi sus A oe ee bee eee ee eee ee eS 34 SMe os avd ta ges eee eee Pee he ee ale EE 34 TST Shad tive we eee Saad ae wore ind aerate Soars ae kw 35 SIO GX A Bilis we EE EEE E E EEE 35 SNOW sie eA ta E Le eRe AR N Aa 35 HO LLL loy di a ton oe ahaa Salles 35 NOUS cabs kee a Cee ee as 35 OLLA is ii AAA ee bas Cees 36 IN 36 ri AAA nn suas ageesen oy 38 ee RES 75 atte AA ee REE EE Een care eee 38 A saad ee ee 39 pic Kpic and PIC KPIC 0 0 cece eee eee 39 DOPLETON iia 40 Opa PUNE dcir 40 OPE CES int A daa GES 40 recen e es 40 EL ase 41 Pascal 4 0 User s Guide Ee peters ba A 41 A E Be eee a 46 a ae cts ors esac oe eee oot cee E Baie eS Setanta 46 S preco iviter mei te See S ps nee See eee dane 46 SDEASU ce cede enti e kee wwe 46 PSs tact o a ee eet ee aye EA 47 HESMPS I sererai id Pate le ee 47 A E tod ese ede OER ok Ra BS 48 AAA A O 49 VA E PENAL EAEE E SA
38. Same as element type record structure 4 Table 8 2 lists the default sizes and alignments of compatible types for FORTRAN and Pascal with the x1 option Table 8 2 Sizes and Alignments of Compatible Types Pascal and FORTRAN with x1 Pascal Type FORTRAN Type Size Bytes Alignment Bytes real real 4 4 integer integer 2 2 2 Precautions with Compatible Types This section describes the precautions you must take when working with character strings and array indexes The FORTRAN Pascal Interface 165 166 Character Strings There are some precautions to take with character strings regarding the null byte passing by value and static storage e Set the byte count to zero before calling Pascal with a null varying string because that is what Pascal assumes about such strings Pass a structure consisting of a 4 byte integer and an array of characters from FORTRAN to a Pascal procedure expecting a var parameter that is a variable length string e Pass by reference by making the strings var in out or in out parameters Set the string to constant because FORTRAN and Pascal each guarantees the null byte only if the string is a constant Neither of them relies on the null byte which is not required by the ISO Pascal Standard Array Indexes The Pascal and FORTRAN array indexes can start at any integer be sure they match Incompatibilities There a
39. a static link to its lexical parent s activation record When an outer block procedure or function is passed as an argument Pascal passes a null pointer in the position normally occupied by the passed routine s static link So that procedures and Pascal 4 0 User s Guide 6 functions can be passed to other languages as arguments the static links for all procedure or function arguments are placed after the end of the conformant array bounds pairs if any Routines in other languages can be passed to Pascal a dummy argument must be passed in the position normally occupied by the passed routine s static link If the passed routine is not a Pascal routine the argument is used only as a placeholder Global Variables in C and Pascal If the types are compatible a global variable can be shared between C and Pascal An example The Pascal procedure var GloVar p Year integer procedure GloVar begin Year 2001 end GloVar The C main program include lt stdio h gt GloVarMain c extern void GloVar int Year int main void Year 2042 GloVar printf d In Year The C Pascal Interface 133 lll O The commands to compile and hostname pe c GloVar p execute GloVar p and hostname ce GloVar o GloVarMain c GloVarMain c without x1 hostnames a out With x1 the Pascal integer 2001 must be paired with a C short int and declared public since the default vis
40. acc command e On the Solaris 2 x environment use the cc command Compilation of Mixed Language Programs You must use the compiler option 1pc when you compile a C main routine that calls Pascal 1pc includes the Pascal object library 1ibpc For example hostname pe c calignmy_pascal p hostname cc my_pascal omy_c c lpc 89 Compatibility of Types for C and Pascal 90 The c option produces an unlinked object file The calign option causes pc to use C like data formats for aggregate objects When you compile a Pascal main routine that calls C you don t have to use any special options but the calign option is again useful The C object library 1ibc is automatically brought in for every Pascal compilation For example hostname cc c my_c c hostname pe calign my_c o my_pascal p Table 6 1 and Table 6 2 list the default sizes and alignments of compatible types for C and Pascal Table 6 1 Cand Pascal Size and Alignment of Compatible Types Pascal Type C Type Size bytes Alignment bytes double double 8 8 longreal double 8 8 real double 8 8 single float 4 4 shortreal float 4 4 integerl6 short int 2 2 integer32 int 4 4 integer int 4 4 128 6 50 124 char 1 1 boolean char 1 1 alfa char a 10 10 1 char char 1 1 string char al80 80 1 varying n of char struct int char n 4 record struct union a Same as element type Pascal 4 0 User
41. demonstrates the use of th debug compiler directive begin writeln Hello how are you debug writeln Fine thank you end debug example hostname pe xl debug p hostname S a out Hello how are you hostname pc xl cond debug p hostname S a out Hello how are you Fine thank you The else Directive The else directive provides an alternative action to the if directive Syntax Sif expression Sthen selse Sendif Pascal 4 0 User s Guide The Pascal program if_then_else p The output when you compile if_then_else p without the config The output when you supply config with the argument red Example program if_then_else output Svar red begin Sif red Sthen writeln It is red selse writeln It is not red Sendif end hostnames pe xl if then else p hostname S a out It is not red hostname pe xl config red if_then_else p hostname a out It is red The Selseif Directive The elseif directive provides an alternative action to the i f directive Syntax Sif expression Sthen selseif expression sthen Sendif Pascal Preprocessor 251 lll aN The Pascal program elseif p The output when you supply config with the argument blue The output when you supply config with the argument red 252 Comments If the expression in if expression Sthen is false pc s
42. expr_example This program generates the following error messages ao d nos O 5 NNNNNNN EH Feb 3050 0070 5550 0030 0240 0230 0220 0230 tname line 16 17 pc expr p 13 13 36 51 1995 expr p Constant string too long lin line line line line line line 18 18 19 20 21 22 Left operand of and must be Boolean not set expression has invalid type Cannot mix sets with integers and reals as operands of files may not participate in comparisons pointers and integers cannot be compared operator was lt Strings not same length in comparison scalars and Booleans cannot be compared operator was Error Diagnostics 213 lll Ko Type Equivalence The Pascal compiler produces several diagnostics that generate the following message non equivalent types In general Pascal considers types to be the same only if they derive from the same type identifier Therefore the following two variables have different types even though the types look the same and have the same characteristics x record a integer b char end y record a integer b char end The assignment x I y produces the following diagnostic messages on Feb 13 14 22 46 1995 inchar p E 25170 line 12 Type clash non identical record types 25560 Type of expression clashed with type of variable in assignment 214 Pascal 4 0 User s Guide
43. f Inthe FORTRAN main program the name is converted to lowercase Uppsercase is ignored The commands to compile and execute PastPtr pand PassPtrmain f program PassPtrmain integer i double precision d integer iptr dptr pointer iPtr i dPtr d iPtr malloc 4 dPtr malloc 8 i 0 d 0 0 call PassPtr write i2 stop end iPtr dPtr 4 1 i d hostname pe c PassPtr p hostnames 77 PassPtr o PassPtrmain f lpfc lpc PassPtrmain f MAIN passptrmain hostname a out 9 99 Function Return Values Function return values match types the same as with parameters and they pass in much the same way See Procedure Calls FORTRAN Pascal on page 168 184 Pascal 4 0 User s Guide Co lll The Pascal function RetReal p The FORTRAN main program RetRealmain f The commands to compile and execute RetReal pand RetRealmain f without x1 Simple Types The simple types pass in a straightforward way as follows function retreal_ var x real real begin retreal_ x 1 end retreal_ double precision r s RetReal r 2 0 s RetReal r write 2f4 1 xr s stop end hostname pe c RetReal p hostnames 77 RetReal o RetRealmain f lpfc lpc RetRealmain f MAIN hostnames a out o 33 00 Type shortreal There is no problem with returning a short real function value between Pascal and FORTRA
44. features Appendix A Pascal Preprocessor describes cppas File Name Extensions Accepted By pc 20 Pascal source files generally use the extension p The compiler recognizes other file name extensions Table 3 1 lists the most important extensions The table notes that pc can produce assembler source files as well as unlinked object files In each case you can pass these partially compiled files to pc which then finishes the compilation linking and loading Table 3 1 File Name Suffixes Recognized by Pascal Suffix Description P Usual extension for Pascal source files pas Valid extension for a Pascal source file The extension instructs pc to put object files in the current directory The default name of the object file is the name of the source file but with a o suffix pi Default extension for Pascal source files that have been processed by the Pascal preprocessor either cpp or cppas 8 Extension for assembler source files that are produced when you call pc with the S option 0 Extension for object files that are generated by the compiler when you call pc with the c option Pascal 4 0 User s Guide Oy lll Option Passing on the Command Line To pass an option on the command line use a dash followed by the option name In some cases you must supply additional information such as a file name For example this command activates the listing option 1 which is off by de
45. for details The fnonstd option causes hardware traps to be enabled for floating point overflow division by zero and invalid operation exceptions These hardware traps are converted into SIGFPE signals and if the program has no SIGFPE handler it terminates with a memory dump fnonstd also causes the math library to be linked in by passing 1m to the linker Solaris 2 x only This option is a synonym for fns ftrap common Solaris 2 x only The fns option turns on the SPARC non standard floating point mode The default is the SPARC standard floating point mode If you compile one routine with fns then compile all routines of the program with the fns option otherwise unexpected results may occur fround r Solaris 2 x only The fround r option sets the IEEE 754 rounding mode that is established during program initialization r must be one of nearest tozero negative positive The Pascal Compiler 29 30 ftrap t The default is fround nearest The meanings are the same as those for the ieee_flags subroutine If you compile one routine with fround r compile all routines of the program with the same fround r option otherwise unexpected results may occur Solaris 2 x only The ftrap t option sets the IEEE 754 trapping mode in effect at startup t is a comma separated list of one or more of the following a11 none common no invalid no overflow no underflow no division
46. function gt rocedure lt function gt B 10290 Fourth argument to lt function gt must be of type lt type gt not lt type gt 10300 First argument to lt function gt cannot be a univ_ptr 10310 lt number gt argument to lt function gt must be of type lt type gt not lt type gt 10320 lt number gt argument to lt function gt must be unpacked 10330 lt number gt argument to lt function gt must be packed 10340 lt function gt line lt number gt has lt number gt arguments 10350 Transfer functions take exactly one argument 10360 sizeof takes at least 1 argument 10370 Formal arguments should be given only in forward declaration 10380 Types must be specified for arguments 10390 Each procedure function argument must be declared separately 10400 lt function gt takes no arguments 10410 lt function gt takes either zero or one argument 10420 lt function gt takes exactly one argument 10430 lt function gt s argument must be integer or real not lt type gt 10440 seed s argument must be an integer not lt type gt 10450 lt function gt s argument must be a real not lt type gt 10460 lt function gt s argument must be an integer or real not lt type gt Error Messages 267 268 10470 ord s argument must be of scalar type not lt type gt 10480 lt function gt s argument must be of scalar type not lt type gt 10490 odd s argument must be an integer not
47. header file is as follows type exception record kind integer name string argl double arg2 double retval double end The element kind is an integer constant that describes the type of exception that occurred and is one of the following constants These constants are defined in the header file Pascal 4 0 User s Guide 11 DOMAIN Argument domain exception SING Argument singularity OVERFLOW Overflow range exception UNDERF LOW Underflow range exception TLOSS Total loss of significance PLOSS Partial loss of significance If your matherr function returns a non zero result no exception message is printed and errno is not set program TestMatherr output include lt math_p h gt begin Case info kind of DOMAIN begin function matherr var info exception change sqrt to return sqrt argl if substr info name 1 length sqrt sqrt then begin info retval sqrt info argl matherr 1 No exception message will be printed end end otherwise matherr 0 end end begin writeln Error handling function writeln sqrt 1 sqrt 1 end Math Libraries 241 libsunmath Support for IEEE Modes and Exceptions ieee_handler is used primarily to establish a signal handler for a particular floating point exception or group of exceptions The syntax of this function is described in the ieee_handler 3M man page
48. home incfiles I usr incfiles program p The preprocessor searches for include and include files in this order 1 In opt SUNWspro SC4 0 include pascal 2 In the directory containing the source file except when you use the include lt file gt form in which case this directory is not searched 3 In directories named with I options if any in left to right order 4 In usr include The i option produces a listing for the specified procedure function tinclude or include file For example this command instructs the compiler to make a listing of the routines in the file scanner i hostname pe i scanner i program p See cpp 1 or Chapter 4 Program Construction and Management or Chapter 5 Separate Compilation for information on include files The keeptmp option keeps temporary files that are created during compilation so they are retained instead of being deleted automatically Pascal 4 0 User s Guide Qo lll L The L option maps all keywords and identifiers to lowercase In Pascal uppercase and lowercase are not interchangeable in identifiers and keywords In standard Pascal the case is insignificant outside of character strings and character constants The L option is most useful for transporting programs from other systems See also the s option 1 The 1 option produces a listing of the program For example hostnames pe l1 random p Pascal PC Version SC4 0 09 J
49. ia n ilb iub for i 1 ton do writeln ia i end Arithmetic Exceptions An arithmetic exception arises when an attempted atomic arithmetic operation does not produce an acceptable result The meaning of the terms atomic and acceptable may vary depending on the context Following are the five types of IEEE floating point exceptions Invalid operation An operand is invalid for the operation about to be performed Math Libraries 239 11 e Division by zero The divisor is zero and the dividend is a finite non zero number or more generally an exact infinite result is delivered by an operation on finite operands Overflow The correctly rounded result is larger than the largest number in the required precision Underflow The number is too small or precision is lost and no signal handler is established for underflow Inexact The rounded result of a valid operation is different from the infinitely precise result This exception occurs whenever there is untrapped overflow or untrapped underflow Math Library Exception Handling Function matherr 240 Some libm functions are specified to call matherr when an exception is detected You can redefine matherr by including a function named matherr in the program When an exception occurs a pointer to the exception structure exc is passed to the user supplied matherr function This structure defined in the math_p h
50. illegal STARG ir_exit no return label cannot take address of op lt identifier gt op lt identifier gt not implemented yet goal lt integer gt not defined for op lt operation gt wasted space lt number gt Error Messages 295 lll Se 296 Pascal 4 0 User s Guide Index A a option to pc command 24 a out 2 8 9 17 address parameters 169 alignment of types in FORTRAN 165 and operator 38 AnswerBook xxii arguments See parameters arithmetic exceptions in math libraries 239 arrays conformant parameters by value 101 114 123 193 as 1 assembler 40 57 assert statement 25 attributes for XView 224 automatic replacement of errors 207 Auto Read definition 61 for dbx disable 61 B B option to pc command 24 b option to pc command 25 block buffering of program output 25 boolean expression 36 38 breaking a program into parts 67 bsdmalloc option to pc command 25 buffering of program output controlling 24 built in function and procedure type errors 211 C C option to pc command 25 49 c option to pc command 26 C programming language 89 to 134 245 arrays by value 114 C calls Pascal 93 to 116 compatible types 90 function return values 115 130 global variables in C and Pascal 133 parameter passing 93 parameters as pointers to procedures 131 Pascal calls C 117 to 132 interface 89 procedures and functions as parameters 131 records and structu
51. in SimValMain c then sr shortreal must be changed to sr real in SimVal p This change is necessary because in C a loat is promoted to double in the absence of function prototypes In x1 mode change sr shortreal to sr longreal Simple Types with x1 With x1 the Pascal real must be paired with a C float and the Pascal integer must be paired with a C short int The C Pascal Interface 113 lll O The Pascal procedure ChrCAVal p The C main program ChrCAValMain c 114 Arrays Since C cannot pass arrays by value it cannot pass strings of characters fixed arrays or univ arrays by value Conformant Arrays Pascal passes all value parameters on the stack or in registers except for value conformant array parameters which are handled by creating a copy in the caller environment and passing a pointer to the copy In addition the bounds of the array must be passed see Conformant Arrays on page 101 This example is the same as the single dimension example in Conformant Arrays except that the var prefix is deleted procedure ChrCAVal a array lb ub integer of char begin a 0 T a 13 o end ChrCAVal include lt stdio h gt extern void ChrCAVal char int int int main void static char s This is a string ChrCAVal s 0 sizeof s 1 printf 11s An s Pascal 4 0 User s Guide The commands to compile and exe
52. is not invoked and a license is not checked out xMerge Solaris 2 x only The xMerge option instructs pc to call the assembler as 1 with the R option This option merges the data segment of the resulting program with the text segment See also R Solaris 1 x only xnolib Same as nolib xnolibmopt Resets fast and does not use the math routine library Use this option after the fast option on the command line as in pc fast xnolibmopt x05 Optimizes the object code Solaris 2 x This option can be combined with g but not with xa When O is used with the g option a limited amount of debugging is available The Pascal Compiler 57 58 Generates the highest level of optimization Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time Optimization at this level is more likely to improve performance if it is done with profile feedback See xprofile p If the optimizer runs out of memory it tries to recover by retrying the current procedure at a lower level of optimization and resumes subsequent procedures at the original level specified in the command line option RXPY Same as p and pg Kprorile p Solaris 2 x only The xprofile p option collects data for a profile or use a profile to optimize p must be collect use name or tcov Pascal 4 0 User s Guide 3 This option causes execution frequency data t
53. is stored in foo bar myprog profile myprog tcovd When running tcov you must pass it the x option to make it use the new style of data If not tcov uses the old d files if any by default for data and produces unexpected output Unlike a the TCOVDIR environment variable has no effect at compile time However its value is used at program runtime The Pascal Compiler 59 60 xregs r Solaris 2 x only The xregs r option specifies the usage of registers for the generated code r is a comma separated list that consists of one or more of the following noslapp1 no float Example xregs appl nosfloat Table 3 7 The xregs Values Value Meaning appl Allow using the registers g2 g3 and g4 In the SPARC ABI these registers are described as application registers Using these registers can increase performance because fewer load and store instructions are needed However such use can conflict with some old library programs written in assembly code nosappl Do not use the app1 registers float Allow using the floating point registers as specified in the SPARC ABI You can use these registers even if the program contains no floating point code no sfloat Do not use the floating point registers With this option a source program cannot contain any floating point code The default is xregs appl float Pascal 4 0 User s Guide Oy lll xXS Solaris 2 x only The xs optio
54. line Override this default by using the xildon option Solaris 2 x only Turns on the incremental linker and forces the use of ild in incremental mode This option is the default if you use the g option and you do not use the G option and there are no source files present on the command line Override this default by using the xildoff option The x1 option implements a set of features that provide broad compatibility with Apollo Pascal We recommend using x1 only when porting Pascal systems from Apollo platforms to SPARC system platforms See the Pascal 4 0 Reference Manual for details of the features controlled by x1 When you use x1 the compiler invokes the cppas preprocessor in place of cpp 1 See Appendix A Pascal Preprocessor for information on cppas Modules compiled with x1 are not compatible with modules compiled without x1 You should not link these two types of modules together xlibmieee xlibmil Same as libmieee Same as libmil Pascal 4 0 User s Guide Qo lll x1libmopt Uses a math routine library optimized for performance The results may be slightly different than those produced by the normal math library This option is implied by the fast option xlicinfo The xlicinfo option returns information about the licensing system In particular it returns the name of the license server and the IDs of users who have licenses checked out When you give this option the compiler
55. local and global optimization induction variable elimination local and global common subexpression elimination algebraic simplification copy propagation constant propagation loop invariant optimization register allocation control flow optimization tail recursion elimination dead code elimination and tail call elimination Level 02 does not optimize references to or definitions of external or indirect variables This level is the appropriate level for device drivers and programs that modify external variables from within signal handlers Pascal 4 0 User s Guide Oy lll 03 x03 Same as 02 but optimizes the uses and definitions of external variables Level 03 does not trace the effects of pointer assignments Do not use Level 03 when compiling device drivers or programs that modify external variables from within signal handlers 04 x03 Same as 03 but traces the effects of pointer assignments and gathers alias information Do not use Level 04 when compiling device drivers or programs that modify external variables from within signal handlers 05 XO5 Solaris 2 x only Generates the highest level of optimization This level uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time Optimization at this level is more likely to improve performance if it is done with profile feedback See xprofile Note Levels 03 and 04 may result
56. of visual or graphical user interfaces for the computer industry Sun holds a non exclusive license from Xerox 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 OLY amp O He Y Contents Preface no shia pase a ene ieee E EERE AN wes xix 1 Introduction RARA ewe sees Standards 0 cece eee een eees Pascal Compiler eee ch tet te he EON EE eS ERE oe Features co 444 eee ee eee ies Compatibility sises arena ye is Sh AAA Text EditGrs 6 oc do oe ee aaa tyne ee a Debug A Cheer ed eer ere ESSEE XView Toolkit p 2 4 654604 ia bot eo E EE aren eed Native Language SUP PON yy 20 oe eee ease ewenee mama nee we Internationalization 0 Iocale 444 46284 viata os Re IES aa
57. optimization t must be one of native generic system name The xtarget option permits a quick and easy specification of the xarch xchip and xcache combinations that occur on real systems The only meaning of xtarget is in its expansion Table 3 8 The xtarget Values Value Meaning native Get the best performance on the host system The compiler generates code for the best performance on the host system It determines the available architecture chip and cache properties of the machine on which the compiler is running generic Get the best performance for generic architecture chip and cache The compiler expands xtarget generic to xarch generic xchip generic xcache generic This is the default value system name Get the best performance for the specified system You select a system name from Table 3 9 that lists the mnemonic encodings of the actual system names and numbers The performance of some programs may benefit by providing the compiler with an accurate description of the target computer hardware When program performance is critical the proper specification of the target hardware could be Pascal 4 0 User s Guide 3 very important This is especially true when running on the newer SPARC processors However for most programs and older SPARC processors the performance gain is negligible and a generic specification is sufficient Each specific value for xtarget expands i
58. pand ext_mod p 260 module include_mod define global proc include extern h procedure proc begin writeln From PROC global global global 1 end proc var global integer procedure proc extern hostname S pe xl include_prog p include_mod p include_prog p include_mod p Linking hostname S a out From MAIN before PROC 1 From PROC I From MAIN after PROC 2 The 1i st Directive The 1ist directive enables a listing of the program Syntax list Pascal 4 0 User s Guide A The Pascal program list p The include file types h Comments The 1ist directive and the 1 compiler option perform the same function Example program list_example output of the list This program demonstrates the us and Snolist directives Slist Sinclude Snolist types h begin pri red yellow true false Cap i TAT 2925 dig 0 100 writeln There are writeln There are writeln There ar writeln There ar list_example blue pos card pos card cap end card pri card dig 4 primary colors 4 possibilities 4 capital letters 4 digits type lowints 0 100 primary_colors possibilities Capital_letters digits set of set of set of lowints var pri pos cap dig primary_colors possibili
59. public variables in an include file Doing so makes it easier to keep your declarations consistent There are other methods for making variables visible to different units See Chapter 5 Separate Compilation for more information Program Construction and Management 73 lll HS Libraries 74 You can use a module unit as a library of useful functions The simplest way to do so is to create a source file containing the definitions of your library routines and then compile it using the c option You can then link the resulting o file to any number of files For convenience you probably should create a header file containing the routine declarations for the library A simple library as described above has two problems When a library grows in size it may become inconvenient to store its source in a single file both for ease of editing and so you can avoid recompiling a large file when you change only part of it On the other hand it would be inconvenient to have to name many library modules on the command line when you link your program Thus it would be helpful to be able to combine a number of library modules Several programs that you run at the same time may share the same library Under the scheme described above each program has its own copy of the library It saves space and even I O time if several programs share library code Both problems have solutions First you can combine or archive modules
60. reply 1 if not f then reply reply 8 if c z then reply reply 64 if i 9 then reply reply 512 if r 9 9 then reply reply 4096 if s 9 then reply reply 32768 end simval_ The FORTRAN main program logical 1 Ey SimValmain f character Cc integer 4 al double precision d integer 2 s integer 4 args data t true p false gt amp Daf DS fp d 9 9 9 call SimVal SVAL t SVAL f SVAL c SVAL i SVAL d SVAL s args write 1 args J format args o6 If nth digit 1 arg n OK stop end The FORTRAN Pascal Interface 181 lll Co The commands to compile and execute SimVal p and SimValmain f 182 hostname pe c SimVal p hostname 77 SimVal o SimValmain f lpfc lpc SimValmain f MAIN hostnames a out args 111111 1f nth digit 1 arg n OK Simple Types with the x1 Option With the x1 option match Pascal real with FORTRAN real and Pascal integer with FORTRAN integer 2 You can pass by value using the VAL feature of FORTRAN Type shortreal Unlike C there is no problem with passing short real value parameters between Pascal and FORTRAN They can be passed exactly as in the previous example with the Pascal short real type matching the FORTRAN real type Arrays Since FORTRAN cannot pass arrays by value it cannot pass strings of characters fixed arrays or univ arrays by value Conformant Arrays Althoug
61. s Guide O lll Table 6 1 Cand Pascal Size and Alignment of Compatible Types Continued Pascal Type C Type Size bytes Alignment bytes array array Same as element type variant record struct union fields in packed bit field record Table 6 2 C and Pascal Size and Alignment of Compatible Types with x1 Pascal Type C Type Size bytes Alignment bytes real float 4 4 integer short int 2 2 Precautions with Compatible Types This section describes the precautions you should take when working with compatible types The short real Type The Pascal shortreal and C float compatibility works if you pass by reference See Value Parameters on page 112 for examples that show you how to pass by value Character Strings C has several assumptions about strings All C strings are e Passed by reference since C strings are arrays Terminated by a null byte e Located in static variable storage You can satisfy these assumptions as follows e Pass by reference by making the strings var in out or in out parameters Provide the null byte explicitly before passing a string to C Pascal guarantees the null byte only if the string is a constant The null byte is not required by the ISO Pascal Standard The C Pascal Interface 91 92 Array Indexes Pascal array indexes can start at any integer C array indexes always start at Zero Aggrega
62. s25 6 Fixed Arrays For a fixed array parameter pass the same type and size by reference as shown in the following example The C Pascal Interface 97 lll O The Pascal procedure FixVec p The C main program FixVecMain c The commands to compile and execute FixVec pand FixVecMain c 98 type VecTyp array 0 8 of integer procedure FixVec var V TVec var Sum integer var i integer begin Sum 0 for i 0 to 8 do Sum Sum V i end FixVec include lt stdio h gt extern void FixVec int int int main void int Sum static int al 0 1 2 3 4 5 6 7 8 FixVec a amp Sum printf d In Sum hostname pe c calign FixVec p hostname cc FixVec o FixVecMain c lpc hostname a out 36 Although it does not apply in this example arrays of aggregates in Pascal have by default a size that is always a multiple of four bytes When you use the calign option to compile the Pascal code that difference with C is eliminated The following example illustrates this point The string Sunday only gets through to the C main program when you compile the Pascal routine using calign Pascal 4 0 User s Guide 6 DS The Pascal procedure type DaysOfWeek p TDay array 0 8 of char TWeek array 0 6 of day TYear array 0 51 of week procedure DaysOfWeek var Y TYear begin v 1 1
63. set lower upper can be tested as follows define LG2BITSLONG 5 log2 bits in long word define LG2BITSWORD 4 log2 bits in short word define MSKBITSLONG 0x1f define MSKBITSHORT 0x0 short setptr set as array of shorts int upper upper bound of the set int elem ordinal value of set element int Ly if setptr elem gt gt LG2BITSWORD 1 lt lt elem MSKBITSWORD elem is in set Pascal 4 0 User s Guide O lll The Pascal procedure IntSetVar p which has an intset of the elements 1 3 7 8 The C main program IntSetVarMain c The commands to compile and execute IntSetVar pand IntSetVarMain c The output of this example depends on the architecture of your machine Pascal int set Type The Pascal int set type is predefined as set of this type takes 16 bytes of storage 0 127 A variable of procedure IntSetVar var s intset begin s 1 3 7 8 end IntSetVar include lt stdio h gt extern void IntSetVar unsigned int int main void int w unsigned int p s s unsigned int malloc 16 IntSetVar s for w 0 p s w lt 4 wH ptt printf 0120 3d An p w printf 110 001 010 binary word 4 n printf 876 543 210 bits word 4 n hostnames pe c IntSetVar p hostname cc IntSetVar o IntSetVarMain c lpc hostnames a out 000000000000 O 000
64. together Secondly you can create a shared library See the Solaris documentation on the linker and libraries for information on creating archived and shared libraries Pascal 4 0 User s Guide Working with Units Separate Compilation 5 This chapter describes how to compile Pascal programs in separate units Chapter 4 Program Construction and Management gives an introduction to the concepts in this chapter Following are the sections Working with Units page 75 Sharing Variables and Routines Across Multiple Units page 76 Sharing Declarations in Multiple Units page 87 In separate compilation a program is divided into several units that can be separately compiled into object o files The object files are then linked using pc which invokes pc3 to check for the consistent use of global names and declarations across the different units and then invokes 1d 1 to link and load the units You can also give pc the names of all the units at once in which case pc compiles all the units checks for consistency and links the units in one step Separate compilation is different from independent compilation In independent compilation you invoke 1d directly so there is no consistency checking Independent compilation is not addressed in this guide Pascal provides two types of source files or units the program unit and the module unit 75 Using Program Units The program unit is the source program
65. units 69 list directive 260 listing the Pascal program 33 1lib option to pc command 34 locale language support 5 logic errors 215 lowercase characters 33 46 M malformed construct errors 208 manuals See documentation math libraries 233 to 243 arithmetic exceptions 239 contents 234 function and procedure prototypes 233 IEEE support functions 236 libm functions 235 libm a 234 libm so 234 libsunmath support 242 libsunmath a 234 301 302 matherr exception handling function 240 Pascal header files 233 SPARC libraries 238 memory out of 217 misalign option to pc command 34 module heading 76 source files 75 unit 69 mt option to pc command 34 mv command 9 N native option to pc command 35 nocx option to pc command 35 nolib option to pc command 35 nolibmil option to pc command 35 Snolist directive 262 nonstandard floating point 29 noqueue licensing option 5 35 Notifier XView 222 not race option to pc command 36 O 0 option to pc command 36 o option to pc command 9 38 object code optimizer 36 object file 18 operating environment See Solaris 2 x Operating system operator and 38 or 38 redirection gt 11 options order of processing 23 to pc command 23 to 66 order of processing options 23 out of memory error 217 output 10 to 13 Pascal 4 0 User s Guide P P option to pc command 36 38 p option to pc command 39 panics
66. when performed at runtime The executable that results from dynamic linking appears in the running process but is not saved to a file It is inefficient for Pascal to send each character to a terminal as it generates its output It is even less efficient if the output is the input of another program such as the line printer daemon 1pr 1 To gain efficiency Pascal buffers output characters it saves the characters in memory until the buffer is full and then outputs the entire buffer in one system interaction By default Pascal output is line buffered Pascal 4 0 User s Guide 3 The b option on the command line turns on block buffering with a block size of 1 024 You cannot turn off buffering from the command line If you give the b option in a comment in the program you can turn off buffering or turn on block buffering The valid values are b0 No buffering b1 Line buffering b2 Block buffering The block size is 1 024 Any number greater than 2 for example b5 is treated as b2 You can only use this option in the main program The block buffering value in effect at the end of the main program is used for the entire program bsdmalloc Solaris 1 x only The bsdmalloc option specifies faster malloc and uses the more efficient malloc from the library 1ibbsdmalloc a This option also causes the flags u _malloc lib libbsdmalloc a to be passed to the linker The C option enables runti
67. with the program header It has the following syntax lt program unit gt lt program heading gt lt declaration list gt lt program body gt Each program you write can have only one program unit The program body is the first code that Pascal executes Using Module Units A module unit is a source program that does not have a program header It has the following syntax lt module unit gt lt moduleheading gt lt declaration list gt The module heading contains the reserved word module followed by an identifier lt module heading gt module lt identifier gt For example module sum This is a legal module heading The module heading is optional Sharing Variables and Routines Across Multiple Units 76 Pascal supports three methods of sharing variables and routines between units include files Multiple variable declarations extern define variable declarations These methods are not mutually exclusive for example you can declare a variable as either extern or define in an include file The following sections describe these methods Pascal 4 0 User s Guide Compiling without the x1 Option The program unit shrvar_prog p The module unit shrvar_mod p The assignment of a new value to global andmax_array in the procedure proc in shrvar_prog pis repeated in shrvar_mod p There are three ways of sharing variables and routines across units when you
68. x1 File Name Suffixes Recognized by Pascal 20 Options That Can Be Passed in Program Text 21 The xarch Valuesy epic ste a cede 51 The xcache Valles ies 53 The chip Valles les 54 The xprofile Values o ooocococcoocccccocccrco 59 The xregs Values cr crcrin irere rnek cece o 60 The xtarget Values 0 0 c eee eee 62 xtarget Expansions 0 cece cece eee 63 C and Pascal Size and Alignment of Compatible Types 90 C and Pascal Size and Alignment of Compatible Types with x1 91 Set Implementation 6666 110 Default Sizes and Alignments of Compatible Types Pascal and FORTRAN inicio cid da ddan ab ated id 165 WM ie 165 xvii xviii Table 10 1 C Declarations to Pascal Declarations Table 11 1 Contents of Math Libraries Pascal 4 0 User s Guide 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 R EADM information E file that accompanies the product contains other release specific Note All references to Pascal in this manual refer to the Pascal 4 0 compiler unless otherwise indicated Operating Environment
69. 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 1ibm and libsunmath functions in Pascal programs Appendix A Pascal Preprocessor describes the Pascal preprocessors with emphasis on the nonstandard preprocessor cppas 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 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 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 Edit your login file Use ls a to list all file
70. 000000000 1 000000000000 2 000000000612 3 110 001 010 binary word 4 876 543 210 bits word 4 The C Pascal Interface 111 lll O Value Parameters There are three types of value parameters in Pascal Simple Types without x1 Without x1 simple types match as in the following example The Pascal procedure procedure SimVal SimVal p t f c i r and s t f boolean are value parameters c char si integerl6 i integer sr shortreal r real var reply integer begin Reply 0 if t then Reply Reply 1 if not f then Reply Reply 8 if c z then Reply Reply 64 if si 9 then Reply Reply 512 if i 9 then Reply Reply 4096 if sr shortreal 9 9 then Reply Reply 32768 if r 9 9 then Reply Reply 262144 end SimVal 112 Pascal 4 0 User s Guide o lll The C main program include lt stdio h gt SimValMain c extern void SimVal char char char short int float double int int main void char t 1 f 0 char c z short si 9 int i 9 float sr 9 9 double E 9 9 int args SimVal t f Cc si i sr Y amp args printf args 060 n args The commands to compile and hostname pe c SimVal p execute SimVal p and hostname cc SimVal o SimValMain c lpc SimValMain c hostname a out args 111111 If no function prototype is provided for SimVal
71. 1 solb5 v7 old 128 32 1 solb6 v8 super 16 32 4 1024 32 1 ultra v8 ultra 16 32 1 512 64 1 ultral 140 v8 ultra 16 32 1 512 64 1 ultral 170 v8 ultra 16 32 1 512 64 1 ultral 1170 v8 ultra 16 32 1 512 64 1 ultral 2170 v8 ultra 16 32 1 512 64 1 ultral 2200 v8 ultra 16 32 1 1024 64 1 The Z option instructs pc to insert code that initializes all local variables to zero Standard Pascal does not allow initialization of variables ztext Solaris 2 x only The ztext option forces a fatal error if relocations remain against non writable allocatable sections Pascal 4 0 User s Guide Units Program Construction and Management 4 This chapter is an introduction to the methods generally used to construct and manage programs using Pascal It describes units and libraries in two separate sections Units page 67 Libraries page 74 For many reasons it is often inconvenient to store a program in a single file as in the case of a very large program You can break up a program in several ways Perhaps the simplest way is to use an include file An include file is a separate file that is copied in by the compiler when it encounters an include compiler directive For example in the following program program include output include includefile the line include includefile is a compiler directive to cpp 1 the Pascal compiler s preprocessor The directive instructs cpp 1 to fin
72. 1024K bytes 32 bytes line size 32 bytes line size 4 way associativity Direct mapping associativity Solaris 2 x only The xchip c option specifies the target processor for use by the optimizer c must be one of generic old super super2 micro micro2 hyper hyper2 powerup ultra Although this option can be used alone it is part of the expansion of the target option its primary use is to provide a value supplied by the target option This option specifies timing properties by specifying the target processor Some effects are The ordering of instructions that is scheduling The way the compiler uses branches The instructions to use in cases where semantically equivalent alternatives are available Table 3 5 The xchip Values Value Meaning generic Use timing properties for good performance on most SPARCs This is the default value that directs the compiler to use the best timing properties for good performance on most SPARC processors without major performance degradation on any of them old Use timing properties of pre SuperSPARC processors super Use timing properties of the SuperSPARC chip super2 Use timing properties of the SuperSPARC II chip micro Use timing properties of the MicroSPARC chip Pascal 4 0 User s Guide Oy lll xcg89 xcg92 XF Table 3 5 The xchip Values Continued Value Meaning micro2 Use timing propertie
73. 290 Length of external label for identifier lt identifier gt exceeds implementation limit 18300 Applied use of lt identifier gt before definition in this block 18320 lt operation gt is forbidden for reals Error Messages 279 280 18420 18430 18440 18450 18460 18470 18480 18490 18500 18510 18520 18530 18540 18550 18560 18580 18590 18600 18610 or oct 18620 Undefined lt identifier gt Undefined identifier Improper lt identifier gt identifier Deleted lt token gt Replaced lt token gt with a lt token gt Replaced lt class gt id with a lt class gt id Inserted lt token gt Expected lt token gt Label lt identifier gt not defined in correct block Label lt identifier gt redefined lt identifier gt is undefined allowed only on files and pointers not on lt type gt s Pascal uses for subscripting not Error occurred on qualification of lt identifier gt division by 0 Variable required in this context Universal pointers may not be dereferenced Illegal format Unknown format radix lt identifier gt ignored expecting hex Expression required Pascal 4 0 User s Guide Ss lll 18630 18640 18650 18660 18670 18680 18690 18700 18710 18720 18730 18740 18750 18760 18770 18780 18790 18800 tp 19010 19020 Unrea
74. 4k io IN 4b OUT 4b pf IN 70pOUT 131p REAL 2 0s 12 core T 0k D 1k io IN 2b OUT 1b pf IN 39p OUT 163p REAL 1 5s 19 core T 0k D 1k io IN 3b OUT 10b pf IN 33p0UT 117p REAL 0 9s 31 core T 0k D 1k io IN 7b OUT 0b pf IN 20pOUT 109p EAL 10 2s 17 core T 0k D 21k io IN 74b0UT 29b pf IN 89pOUT 184p 48 Each line begins with the name of the compiler pass The rest of the line is divided into four parts time core io and pf time gives the time used by that pass of the compiler in this order a User time b System time c Total CPU time which is the sum of user and system time d Real clock time e Percent of real time used by CPU time core gives memory usage statistics for the pass in this order a The first item is always 0 and currently has no meaning b The second item is the integral resident set size The io section gives the volume of input and output operations expressed in blocks The pf section gives the amount of page faults expressed in pages in this order a Page faults not requiring physical I O b Page faults requiring physical I O Pascal 4 0 User s Guide Oy lll U name The U option removes any initial definition of the cpp 1 symbol name See cpp 1 for more information You cannot use this option with the x1 option V The V option prints the version number of each compilation pass VO and V1 The v0 and v1 options turn on sets of options that insert c
75. 9 Reply 010000 if sr float 9 9 Reply 0100000 if r 9 9 Reply 01000000 158 Pascal 4 0 User s Guide The Pascal main program program SimValMain output SimValMain p var t boolean true f boolean false c char iz si integerl6 9 i integer 9 sr shortreal 9 9 r real p 9 9 args integer procedure SimVal t f boolean en char si integerl6 i integer sr shortreal r real var Reply integer external C begin SimVal t f c si i Sr Y args writeln args args 7 oct end The commands to compile and hostname CC c SimVal cc execute SimVal cc and hostname pe SimVal o SimValMain p SimValMain p hostname a out args 111111 Function Return Values Function return values match types in the same manner as with parameters They pass in much the same way The C Pascal Interface 159 lll N The C function RetReal cc The Pascal main program RetRealMain p The commands to compile and execute RetReal cc and RetRealMain p 160 The following example shows how to pass simple types extern Cc double RetReal double amp x return x 1 0 program RetRealMain output var r s real function RetReal var x real real external C begin r 2 0 RetReal r S a r writeln r 4 1 Return st 43 end CC c RetReal cc hostnames pc RetReal o
76. 93 294 25670 Index type for arrays cannot be real 25680 Array index type is a lt type gt not a range or scalar as required 25690 Packed conformant array schema requires type identifier as element type 25700 Illegal type in VARYING array only type CHAR allowed 25710 Size of lt type gt type exceeds implementation limits 25720 Initializer must be a constant value of same type 26010 Malformed program statement 26020 Malformed declaration 26030 Malformed const declaration 26040 Malformed type declaration 26050 Malformed var declaration 26060 Malformed record declaration 26070 Malformed statement in case 26080 Malformed statement 26090 Missing malformed expression 26100 Label restricted to 4 digits 26110 Label declared non integer 26120 Replaced unknown parameter specifier lt identifier gt with OUT 26130 Deleted before keyword else Pascal 4 0 User s Guide Ss lll 26140 27010 Extension to WITH statement not allowed Integer overflow in constant expression The following are internal error messages If any of them is displayed contact Sun Customer Support 18330 18340 18350 18360 18370 18380 18390 18400 18410 18570 NAME with no symbol table entry ir_symbol unknown class ir_leaf cannot take address of op lt identifier gt ir_leaf illegal leaf node op lt identifier gt ir_starg
77. AVar s 0 sizeof s 1 printf lls An s s lower upper Pascal 4 0 User s Guide o lll The commands to compile and execute ChrCAVar pand ChrCAVarMain c The Pascal procedure StruChr p Itis safer for the Pascal procedure to explicitly provide the null byte and include itin the count before the string is passed to C hostname pe c calign ChrCAVar p hostnames cc ChrCAVar o ChrCAVarMain c lpc hostnames a out This is a string Records and Structures In most cases a Pascal record describes the same objects as its C structure equivalent provided that the components have compatible types and are declared in the same order The compatibility of the types depends mostly on size and alignment For more information on size and alignments of simple components see Compatibility of Types for C and Pascal on page 90 By default the alignment of a record is always four bytes and the size of a record is always a multiple of four bytes However when you use calign in compiling the Pascal code the size and alignment of the Pascal record matches the size and alignment of the equivalent C structure A Pascal record of an integer and a character string matches a C structure of the same constructs as follows type TLenStr record nbytes integer chrstr array 0 24 of char end procedure StruChr var v TLenStr begin v NBytes 14 v ChrStr St Petersburg chr 0
78. Main p hostname a out 1 2 3 162 Pascal 4 0 User s Guide The FORTRAN Pascal Interface This chapter describes how to mix FORTRAN 77 and Pascal modules in the same program It contains the following sections Compiler Mixed Language Programs page 163 Compatibility of Types for FORTRAN and Pascal page 164 General Parameter Passing in FORTRAN and Pascal page 167 Procedure Calls FORTRAN Pascal page 168 Procedure Calls Pascal FORTRAN page 185 Routines as Parameters page 202 Compiler Mixed Language Programs When you compile with the v verbose option the Pascal driver brings in the runtime libraries for the main module However when you compile a module that is not the main module and which is written in a language different from the main module you must explicitly bring in the runtime library on the command line For example you must use the compiler options lpfc and 1pc when you compile a FORTRAN main routine that calls Pascal The lpfc option links the common startup code for programs containing mixed Pascal and FORTRAN object libraries The 1pc option includes the Pascal object library libpc 163 Specify lpfc on the command line before 1pc For example hostname S pe c my_pascal p hostname s 77 my_pascal o my_fortran f lpfc lpc Sampmain f MAIN The c option to pc produces an unlinked object file When you compile a Pascal mai
79. N Simple Types Passed by Reference Simple types pass in a straightforward manner as follows The C function SimRef cc extern C char char char int short float double O PA fm ct tool wo Oo OF Nos K l void SimRef amp t St amp C amp i amp S amp r amp d 156 Pascal 4 0 User s Guide N lll The Pascal main program program SimRefMain output SimRefMain p var t f boolean c char i integer s integerl6 r shortreal d real procedure SimRef var t f boolean var c char var i integer var s integerl6 var r shortreal var d real external C begin SimRef t f c i s Y d writeln E 6 c 2 i 2 st 2 4 1 ds 4 1 end The commands to compile and hostname CC c SimRef cc execute SimRef cc and hostname pe SimRef o SimRefMain p SimRefMain p hostname a out true false z 9 9 9 9 9 9 Arguments Passed by Value Pascal arguments can also be passed by value Here is how they work with C The C 4 Pascal Interface 157 lll N Simple Types Simple types match with value parameters See the following example The C function SimVal cc extern C void SimVal char E char Es char cy short si int dy float sr double r int Reply Reply 0 if t Reply 01 if Cl f Reply 010 if c z Reply 0100 1f si 9 Reply 01000 if i
80. N As in the previous example it can be passed exactly with the Pascal shortreal type matching the FORTRAN real type without x1 Procedure Calls Pascal FORTRAN This section parallels Procedure Calls FORTRAN Pascal on page 168 The comments and restrictions given in that section apply here also The FORTRAN Pascal Interface 185 lll Co Variable Parameters Pascal passes all var parameters by reference the FORTRAN default Simple Types Simple types pass in a straightforward manner as follows The FORTRAN subroutine subroutine SimVar t f c i dd si sr SimVar f logical 1 ty E character E integer i double precision d integer 2 si real sr t Ese f false hg i 9 d 9 9 si 9 sr 9 9 return end 186 Pascal 4 0 User s Guide The Pascal main program SimVarmain p The commands to compile and execute SimVar p and SimVarmain p program SimVarmain output var t boolean ee char i integer r real si integerl6 sr shortreal procedure simvar var t f boolean var c char var i integer var r real var si integerl6 var sr shortreal external fortran begin simvar t E i si si writeln t f 6 c 2 i 2 r 4 1 si 2 sr 4 end SimVarmain hostname 77 c SimVar f SimVar f simvar hostnames pc SimVar o SimVarmain p lpfc 1F77 hostname S a out true false z 9 9 9 9 9 9 Strin
81. Pascal 4 0 User s Guide amp SunSoft 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 1100 U S A All rights reserved This product or document is protected by copyright and distributed under licenses restricting 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 protected 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 Technical Data and Computer Software clause at DFARS 252 227 7013 and FAR 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 ProWorks ProWorks TeamWare ProCompiler Sun 4 SunOS ONC ONC
82. RetRealMain p hostname S a out 2 0 Return 3 0 hostname Pascal 4 0 User s Guide Global Variables in C and Pascal If the types are compatible a global variable can be shared between C and Pascal See this example The Pascal procedure var GloVar p Year integer procedure GloVar begin Year 1995 end The C main program include lt stdio h gt GloVarMain cc extern C void GloVar int Year int main void Year 2042 GloVar printf d An Year The commands to compile and hostname pe c GloVar p execute GloVar p and hostname CC GloVar o GloVarMain cc lpc GloVarMain cc hostname a out 1995 The C Pascal Interface 161 4 Pascal File Pointers to C You can pass this example a file pointer from Pascal to C then have C do the I O See The C procedure include lt stdio h gt UseFilePtr cc extern C void UseFilePtr FILE ptr fprintf ptr 1 An fprintf ptr 2 An fprintf ptr 3 An The C main program program UseFilePtrMain output UseFilePtrMain p var f text cfile univ_ptr procedure UseFilePtr cf univ_ptr external C begin rewrite f myfile data cfile getfile f UseFilePtr cfile end The commands to compile and hostname CC c UseFilePtr cc execute UseFilePtr cc and hostname pe UseFilePtr o UseFilePtrMain p UseFilePtr
83. Routine Options are not standard 23080 External procedures 23090 Separately compiled standard 23100 UNIV parameters are non standard 23110 IN parameters are non standard 23120 OUT parameters are non standard 23130 IN OUT parameters are non standard 23140 lt identifier gt is a nonstandard function 23150 OTHERWISE clause in 23160 Ranges in case statements are non standard 23170 Transfer functions are non standard 23180 23190 23200 Zero widths are non standard 23210 Oct and hex are non standard 23220 Writing lt fype gt s to text files is non standard 23230 lt identifier gt is a nonstandard procedure 23240 Short circuit operators are non standard 23250 lt operator gt comparison on sets is non standard 23260 record comparison is non standard Error Messages 287 288 23270 Storage Class non standard 23280 Initialization in declaration part is non standard 23290 UNIV_PTR types are non standard 23300 _ in an identifier is nonstandard 23310 Octal constants are non standard 23320 lt operator gt is non standard 24010 Cannot exit not within a loop 24020 For statement variable lt identifier gt must be unqualified 24030 For statement variable lt identifier gt cannot be an element of a record 24040 For statement variable lt identifier gt may be illegally changed at line lt number gt 24050 For statement variable lt identifier gt must be declared in the block in
84. Samp p Note the procedure definition The procedure name in the procedure statement is in lowercase with a trailing underscore _ This format is required to match the conventions of the FORTRAN compiler var parameters are used to match FORTRAN defaults The FORTRAN main program Sampmain f Note the procedure declaration and call FORTRAN converts to lowercase by default you do not explicitly give the underscore _ The commands to compile and execute Samp p and Sampmain f Here are examples of how a FORTRAN main program calls a Pascal procedure procedure samp_ var i integer var r real begin i 9 E 139 9 end samp_ integer 1 double precision d call Samp i d write 12 F4 1 i d stop end hostnames pe c Samp p hostnames 77 Samp o Sampmain f lpfc lpc Sampmain f MAIN hostname a out 9 9 9 Variable Parameters 168 Pascal passes all var parameters by reference FORTRAN s default Simple Types without the x1 Option With var parameters simple types match Pascal 4 0 User s Guide The Pascal procedure SimVar p The FORTRAN main program SimVarmain f The commands to compile and execute SimVar p and SimVarmain f See the following example procedure simvar_ var t f boolean var c char var i integer var r real var si integerl6 var sr shortreal begin true f false c j t2 i 9 r i 9 9
85. Sum integer V array 0 2 of integer begin V O 7 V 1 8 V 2 9 univec V 2 Sum writeln Sum end UniVec integer fortran Pascal 4 0 User s Guide The commands to compile and execute UniVec f and UniVecmain p hostname S 77 c UniVec f UniVec f univec hostnames pe UniVec o UniVecmain p lpfc 1F77 hostname S a out 24 Conformant Arrays Pascal conformant array parameters are not compatible if Pascal calls FORTRAN The FORTRAN Pascal Interface 193 111 Co Records and Structures Records and structures pass as follows The FORTRAN subroutine subroutine StruChr vls StruChr f structure VarLenStr integer nbytes character a 25 end structure record VarLenStr vls vis a 1 5 oyvay vis nbytes 5 return end The Pascal main program program StruChrmain StruChrmain p type lenstr record nbytes integer chrstr array 0 25 of char end var v lenstr procedure struchr var v lenstr external fortran begin struchr v writeln v chrstr v chrstr writeln v nbytes v nbytes 2 end StruChrmain 194 Pascal 4 0 User s Guide The commands to compile and execute St ruChr f and StruChrmain p hostnames 77 c StruChr f StruChr f struchr hostnames pe StruChr o StruChrmain p lpfc 1F77 hostname S a out v chrstr oyvay v nbytes 5 Variant Records
86. UniVec c The Pascal main program UniVecMain p The commands to compile and execute UniVec c and UniVecMain p 122 The univ Arrays The univ arrays that are in out in out or var parameters pass by reference Here is an example var Sum external c integer begin V O 7 V 1 8 V 2 9 UniVec V 2 writeln Sum UniVecMain Sum end void UniVec int V 3 int Last int Sum int i Sum 0 for i 0 i lt Last i Sum V il program UniVecMain output type TVec array 0 9 of integer var Sum integer V array 0 2 of integer procedure UniVec var V univ TVec in Last integer hostname S cc c UniVec c hostname S a out 24 hostname pe calign UniVec o UniVecMain p Pascal 4 0 User s Guide 6 The C function IntCA c The Pascal main program IntCAMain p Note that what Pascal passes as s is received inC as a 1b ub The calign option is not needed for this example but may be necessary if the array parameter is an array of aggregates Conformant Arrays For single dimension conformant arrays pass upper and lower bounds placed after the declared parameter list If the array is multidimensional pass element widths as well one element width for each dimension except the last one Chapter 8 The FORTRAN Pascal Interface has an example of multidimensional conformant array passing Th
87. WS AnswerBook et Magnify Help sont des marques depos es ou enregistr es par Sun Microsystems Inc aux Etats Unis et dans certains autres pays UNIX est une marque enregistr e aux Etats Unis et dans d autres pays et exclusivement licenci e par X Open Company Ltd OPEN LOOK est une marque enregistr e de Novell Inc PostScript et Display PostScript sont des marques d Adobe Systems Inc PowerPC est une marque depos e de International Business Machines Corporation HP and HP UX sont des marques enregistr es par Hewlett Packard Company Toutes les marques SPARC sont des marques depos es ou enregitr es de SPARC International Inc aux Etats Unis et dans d autres pays SPARCcenter SPARCcluster SPARCompiler SPARCdesign SPARC811 SPARCengine SPARCprinter SPARCserver SPARstation SPARCstorage SPARCworks microSPARC microSPARC II et UltraSPARC sont exclusivement licenci es a Sun Microsystems Inc Les produits portant les marques sont bas s sur une architecture d velopp e par Sun Microsystems Inc Les utilisateurs d interfaces graphiques OPEN LOOK et Sun ont t d velopp s par Sun Microsystems Inc pour ses utilisateurs et licenci s Sun reconnait les efforts de pionniers de Xerox pour la recherche et le d veloppement du concept des interfaces d utilisation visuelle ou graphique pour l industrie de l informatique Sun d tient une licence non exclusive de Xerox sur l interface d utilisation graphique cette lic
88. _retrospective SPARC Libraries 238 The libm function i call i The libm and libsunmath libraries also contain Argument reduction functions using infinitely precise Pi and trigonometric functions scaled in Pi Data conversion routines for converting floating point data between IEEE and non IEEE formats Random number generators There are two facilities for generating uniform pseudo random numbers addrans 3M and lcrans 3M addrans is an additive random number generator lcrans is a linear congruential random number generator In addition shufrans 3M shuffles a set of pseudo random numbers to provide even more randomness for applications that need it Pascal 4 0 User s Guide _retrospective prints to stderr information about unrequited exceptions and nonstandard IEEE modes Pascal programs _retrospective on exit by default 11 program TestRandom output include math_p h var n integer 100 i integer ilb Lower bound iub integer Upper bound la array 1 100 of integer begin writeln Integer linear congruential random number generator ilb I_LCRAN_LB iub I_LCRAN_UB i_lcrans_ ia n ilb iub for i 1 ton do writeln ia il writeln Integer additive random number generator ilb minint iub maxint i_addrans_ ia n ilb iub for i 1 ton do writeln ia il writeln Integer random number shufflers i_shufrans_
89. ables of that type Solaris 1 x only The cg89 option generates code to run on generic SPARC architecture Solaris 2 x only This option is a macro for xarch v7 xchip old xcache 64 32 1 Solaris 1 x only The cg92 option generates code to run on SPARC V8 architecture Solaris 2 x only This option is a macro for xarch v8 xchip super xcache 16 64 4 1024 64 1 You can only use this option when you also use the x1 option Pascal 4 0 User s Guide 3 COnL 1g The cond option instructs pc to compile the lines in your program that begin with the debug compiler directive If you compile your program without cond pc treats lines with the debug directive as comments x1 runs your pro through the preprocessor cppas which handles the Apollo DOMAIN style Pascal compiler directives such as debug See Appendix A Pascal Preprocessor for a complete description of conditional variables cppas and compiler directives You can only use this option when you also use the x1 option The config option sets a conditional variable to true You can only use this option when you use the preprocessor cppas which is invoked when you use the x1 option Pascal supports the config option with only one value For example Pascal accepts config one but not config one two To specify more than one variable use multiple config options on the command line If you use config but do not give a varia
90. ache C Solaris 2 x only The xcache c option defines the cache properties for use by the optimizer c must be one of the following generic s1 11 a1 s1 11 a1 52 12 a2 s1 11 a1 s2 12 a2 s3 13 a3 The si li ai are defined as follows si The size of the data cache at level i in kilobytes li The line size of the data cache at level i in bytes ai The associativity of the data cache at level i Although this option can be used alone it is part of the expansion of the target option its primary use is to override a value supplied by the target option This option specifies the cache properties that the optimizer can use It does not guarantee that any particular cache property is used Table 3 4 The xcache Values Value generic Meaning Define the cache properties for good performance on most SPARCs This is the default value which directs the compiler to use cache properties for good performance on most SPARC processors without major performance degradation on any of them With each new release these best timing properties will be adjusted if appropriate s1 11 a1 Define level 1 cache properties s1 l1 a1 s2 12 a2 Define levels 1 and 2 cache properties s1 11 a1 s2 12 a2 s3 13 a3 Define levels 1 2 and 3 cache properties The Pascal Compiler 53 54 xchip c Example xcache 16 32 4 1024 32 1 specifies the following Level 1 cache has Level 2 cache has 16K bytes
91. ack Thus you need not create otherwise useless temporary variables The compiler appends an underscore to the name of the external procedure to conform to a naming convention of the 77 1 compiler Pascal procedure names called from FORTRAN must supply their own trailing underscore _ Multidimensional Pascal arrays are not compatible with FORTRAN arrays Because FORTRAN uses column major ordering a multidimensional Pascal array passed to FORTRAN appears transposed For routines declared extern c or external c a warning is generated if you attempt to pass a nested function When you compile your program with the x1 option you can also use nonpascal to declare non Pascal routines when porting DOMAIN programs written in DOMAIN Pascal FORTRAN and C Pascal 4 0 User s Guide The C Pascal Interface 6 This chapter describes how to mix C and Pascal modules in the same program It contains the following sections Compilation of Mixed Language Programs page 89 Compatibility of Types for C and Pascal page 90 General Parameter Passing in C and Pascal page 93 Procedure Calls C Pascal page 93 Procedure Calls Pascal C page 117 Procedures and Functions as Parameters page 132 Global Variables in C and Pascal page 133 File Passing Between Pascal and C page 134 The examples in this chapter assume that you are using the ANSI C compiler To invoke ANSI C e On the Solaris 1 x environment use the
92. al Level 0 and 1 1 46 statement define 27 assert 25 stdin 10 stdout 10 string errors 206 symbol errors 208 table for dbx 61 syntax errors and recovery 205 to 207 T tc option to pc command 47 tcov 1 utility 24 temp option to pc command 47 text editor textedit 3 vi 3 time option to pc command 48 type equivalence errors 214 shortreal 154 182 sizes See sizes of types types compatible in C and Pascal 90 compatible in C and Pascal 138 compatible in FORTRAN and Pascal 165 enumerated 92 166 incompatible 210 set 93 110 167 179 U U option to pc command 49 uninitialized variable error 216 units compiling and linking 69 introductory information 67 to 73 separately compiled 68 sharing routines 76 to 88 sharing variables 71 to 73 76 to 86 unreachable statements errors 215 unused item errors 216 Index uppercase characters 33 46 usr include 32 V V option to pc command 17 v option to pc command 49 value conformant array parameters 101 114 123 182 193 value parameters with C 129 130 with C 152 with FORTRAN 181 197 svar directive 247 258 263 variable conditional 27 246 define 82 initialization of and errors 216 parameters 94 with C 117 128 with C 161 with FORTRAN 168 private 73 80 public 73 80 variables and routines sharing across multiple units using define variable 82 using define declaration 83 using extern variab
93. al char s int len for_NonPascal s 18 int i for i 0 i lt len i putchar s i putchar n program NonPasMain var s string procedure for_C var s string len integer xternal c procedure for_NonPascal var s string len integer nonpascal begin s Hello from Pascal for C s 18 end NonPasMain hostname cc c NonPas c hostnames pe NonPas o NonPasMain p hostname S a out Hello from Pascal Hello from Pascal Pascal 4 0 User s Guide Value Parameters The C function SimVal c In general Pascal passes value parameters in registers or on the stack widening to a full word if necessary Simple Types With value parameters simple types match as in the following example void SimVal char Es char f char Cy short si int diy float sr double fy int reply reply 0 if t if f if c z if si 9 if i 9 if sr float 9 9 if r 9 9 reply reply reply reply reply reply reply 01 010 0100 01000 010000 0100000 01000000 The C Pascal Interface 129 lll O The Pascal main program SimValMain p The commands to compile and execute SimVal cand SimValMain p program SimVal output var t boolean true f boolean false c char p ge si integerl6 i integer sr shortreal r double arg
94. al page 138 Procedure Calls Pascal C page 155 Global Variables in C and Pascal page 161 Pascal File Pointers to C page 162 You must use the compiler option 1pc when you use CC to link a C main routine that calls Pascal 1pc denotes linking with the Pascal runtime support library libpc On the Solaris 1 x environment if you use pc to link you must add the 1c option The calign option causes pc to use data formats for aggregate objects similar to those in C 137 4 Compatibility of Types for C and Pascal C Name Encoding Table 6 1 and Table 6 2 on page 90 list the default sizes and alignments of compatible types for C and Pascal They apply to C as well To implement function overloading and type safe linkage the C compiler normally appends type information to the function names To prevent the C compiler from doing so and to allow Pascal to call a C function declare the C function with the extern C language construct One common way to do this is in the declaration of a function like this extern C void f int void f int body of fess For brevity you can also combine extern C with the definition of the function as in extern C void f int body of f Procedure Calls C Pascal The Pascal procedure Samp in the file Samp p 138 Following are examples that illustrate how a C main program calls a Pascal
95. an 1995 Pascal 4 0 Mon Jan 09 09 04 1995 random p 1 program random_number output 2 var 4 i integer 5 integer 6 7 begin 8 for i 1 to 5 do begin 9 write trunc random x 101 10 end 11 writeln 12 end The first line identifies the version of the compiler you are using The next line gives the modification time of the file being compiled The remainder of the listing is the source program Ldirectory The Ldirectory option adds directory to the 1d library search path for 1d The Pascal Compiler 33 34 libmieee Va om L llib Forces IEEE 754 style return values for math routines in exceptional cases In such cases no exception message is printed and errno is not set The libmil option instructs the compiler to select the best inline templates for the floating point option and operating system release available on this system The 1 1b option links 1d 1 with the object library lib Do not use the 1ucb option because Pascal is not compatible with the object library Libucb misalign Mt The misalign option allows for misaligned data in memory Use this option only if you receive a warning message that your data is misaligned With the misalign option pc generates much slower code for references to formal parameters If possible recode the indicated section instead of recompiling your program with this option The mt option uses multithread safe libraries eliminates confli
96. and 32 i option to pc command 32 I O errors 212 217 identifier errors 208 identifiers 33 46 76 IEEE support functions in math libraries 236 Sif directive 247 257 ifdef directive 255 257 258 illegal characters 205 include directive 67 Sinclude directive 259 263 include file 84 257 and library header files 74 as header file 70 introduction 67 producing a listing of 32 search order 32 to break a program up 67 incompatible type errors 210 inline 1 procedure call expander 40 input 10 to 13 installation xix interface C Pascal 137 C Pascal 89 FORTRAN Pascal 163 internationalization 4 iropt 40 K keeptmp option to pc command 32 keyword 33 46 Kpic and KPIC options to pc command 39 L L option to pc command 33 1 option to pc command 33 261 language support See internationalization 1d 1 linker 26 34 40 Ldirectory option to pc command 33 Level 0 standard Pascal 1 46 Level 1 standard Pascal 1 46 Index lib object library 34 libm functions in math libraries 235 libm a math library 234 libm so math library 234 libmieee option to pc command 34 libmil option to pc command 34 libraries compiling with XView 224 creating 74 libsunmath support in math libraries 242 libsunmath a math library 234 licensing 5 noqueue option 5 queuing 5 status 5 xlicinfo option 5 line buffering of program output 24 linelimit procedure 25 linking
97. and of must be integer or real not lt type gt 20070 Left operand of lt operator gt must be Boolean not lt type gt N 0080 Right operand of lt operator gt must be Boolean not lt type gt N 0090 Left operand of lt operator gt must be integer not lt type gt N 0100 Right operand of lt operator gt must be integer not lt type gt N 0110 Right operand of in must be a set not lt type gt 20120 Operands of are of incompatible types 20130 Operand of lt operator gt must be integer or real not lt type gt Pascal 4 0 User s Guide Ss lll N 0140 Operands of lt operator gt must both be sets N 0150 Set types of operands of lt operator gt must be compatible N 0160 Incorrect statement usage const with operand 20170 allowed only on files and pointers not on lt type gt s 20180 lt operation gt is an illegal operation on strings 20190 not must operate on a Boolean or Integer not lt type gt N 0200 not must operate on a Boolean not lt type gt 0210 lt operation gt not allowed on pointers only allow and AN N 0220 Strings not same length in lt operator gt comparison N 0230 lt identifier gt s and lt identifier gt s cannot be compared operator was lt operator gt N 0240 lt identifier gt s may not participate in comparisons 21010 Attempt to pass IN parameter to formal reference parameter 21020 Expres
98. ar TWeather 21 Y extern void DayWeather struct TDayRec int int main void char s25 25 char t25 25 struct TDayRec dr 2 int nbytes 0 DayWeather dr amp nbytes strncpy s25 dr 1 TDay 6 printf day s An s25 strncpy t25 dr 1 TWeather nbytes printf weather s An t25 The C Pascal Interface 107 lll O The commands to compile and execute DayWeather p and DayWeatherMain c without calign The commands to compile and execute DayWeather p and DayWeatherMain c with calign The Pascal procedure VarRec p 108 When you compile the Pascal routine without using the calign option the program does not work correctly hostname pe c DayWeather p hostname S cc DayWeather o DayWeatherMain c lpc hostname a out day weather sun hostname pe calign c DayWeather p hostname S cc DayWeather o DayWeatherMain c lpc hostname a out day Sunday weather sunny Variant Records C equivalents of variant records can sometimes be constructed although there is some variation with architecture and sometimes a need to adjust alignment You can avoid the need to adjust alignment by using the calign option type vr record case tag char of ra e chl ch2 char b flag boolean K ALIGN integer end procedure VarRec var x vr begin if x chl a then x ch2 i Z end VarRec
99. ariable global is in the include file inc_prog2 p and is therefore included in both files The define declaration in file inc_mod2 p cancels the extern definition 84 Pascal 4 0 User s Guide The program unit inc_prog2 p The module unit inc_mod2 p The include file include2 h program inc_prog2 Sinclude include2 h procedure proc extern begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end proc module inc_mod2 define global Sinclude include2 h procedure proc begin writeln From PROC global global global 1 end proc var global extern integer Separate Compilation 85 lll a The commands to compile and execute inc_prog2 pand inc_mod2 p The program unit ext_prog p 86 hostname S pe xl inc_prog2 p inc_mod2 p inc_prog2 p inc_mod2 p Linking hostname S a out From MAIN before PROC 1 From PROC I From MAIN after PROC 2 Using extern In the previous example the extern definition for variables is put into an include file and then shared You can do the same for the extern procedure definition In doing so you must also declare the variable with a define declaration in the module that defines the procedure This declaration nullifies the effect of the extern declaration program ext_prog Sinclude extern h begin
100. aring it a subclass of some class The new class is called a child or descendant class the old class is called a superclass parent or ancestor class A descendant can itself have descendants Thus classes form a tree structure Pascal 4 0 User s Guide 10 Pascal Interface with the root being the class from which all others are descended In the XView toolkit the root is the class Generic Object which has no data fields and no methods Each descendant of Generic Object is specialized in some way perhaps with additional data fields or methods What gives object orientation its power is that the inherited methods of a subclass can be reimplemented so that they take actions suited to the subclass For example consider a system that has three classes Drawable Object Window and Icon Window and Icon are subclasses of Drawable Object This setup creates the hierarchical relationship illustrated in Figure 10 1 Drawable Object Window Figure 10 1 A Sample Class Hierarchy Suppose that Drawable Object has a method that draws the object Window and Icon inherit that method but each implements it in a different way Window defines a Draw method that draws windows Icon defines a Draw method that draws icons When you write your program you can send a message to an object directing it to draw itself without knowing whether at runtime the object is an icon or a window This method works because both Window and Icon are d
101. as a last argument an argument of type Attr_avlist This type is a pointer to an array of attributes and values The special routines are xv_init_1 xv_create_1 xv_find_1 selection_ask_1 selection_init_request_1 The XView Toolkit 225 10 Here mymenu is an object of type XV_object 226 Handles Data Types Example calls are mymenu xv_creat NULL MENU 0 ncols get_MENU_NCOLS mymenu set_MENU_NITEMS mymenu items xv_find_l mymenu MENU attr_create_list_2s MENU_DEFAULT 4 xv_destroy mymenu The lists for Attr_avlist are created by functions that have the following names attr_create_list_n attr_create_list_ns The n indicates the number of arguments the routine accepts The number of arguments can be 1 16 The routines ending in s return a pointer to a static attribute value array which is reused with each call to the static list routines The versions without the s return a dynamically allocated list which should be passed to xv_destroy when you are finished with it When you create an XView object xv_create returns a handle for that object You pass this handle to the appropriate procedure for manipulating the object Each XView object has its own specific data type The name of an object s data type always starts with a capital letter For example the data type for a scrollbar is Scrollbar T
102. as both a field and a type name in a the bl 14170 14180 14190 declarations 14200 14210 14220 STATIC is ignored 14230 DEFINE is ignored 14240 EXTERN is ignored 14250 lt identifier gt 14260 lt identifier gt 14270 record definition 14280 14290 Pascal 4 0 cannot DEFINE lt identifier gt variable was not previously declared as EXT ERN Declaration found when statement expected User s Guide E B 14300 Expected keyword begin after declarations before statements 14310 Improper initialization for variable lt identifier gt 14320 lt identifier gt is already defined globally 14330 Definition of name lt identifier gt after applied use in lt identifier gt 14340 Definition of name lt identifier gt after applied use 14350 lt identifier gt is already defined in this block 14360 Range lower bound exceeds upper bound 14370 subrange descriptor used in illegal context 14380 Cannot initialize dynamic local variables 15010 File lt identifier gt listed in program statement but not declared 15020 File lt identifier gt listed in program statement but declared as a lt identifier gt 15030 File lt identifier gt listed in program statement but defined as lt identifier gt 15040 15050 value 15060 15070 15080 15090 Files cannot be passed by value Files cannot be a component of lt identifier gt
103. ble the value of the predefined conditional variable config is set to true x1 runs your program through the preprocessor cppas which handles the Apollo DOMAIN style Pascal compiler directives such as config See Appendix A Pascal Preprocessor for a complete description of conditional variables cppas and compiler directives Dname def The D option defines a symbol name to the C preprocessor cpp It is equivalent to using the define statement in your program If you do not include a definition name is defined as 1 See cpp 1 for more information If you use this option with the x1 option D is equivalent to using the sconfig directive in your program The Pascal Compiler 27 28 dalign dn dryrun dy fast The dalign option instructs the compiler to generate double load and store instructions wherever possible for faster execution All double typed data become double aligned so do not use this option when correct alignment is not ensured Solaris 2 x only The dn option specifies static linking in the link editor The dryrun option instructs the compiler to show but not execute the commands constructed by the compilation driver You can then see the order of execution of compiler passes without actually executing them Solaris 2 x only The dy option specifies dynamic linking in the link editor Solaris 1 x only The fast option selects optimum compilation opti
104. c and VarRecMain p program VarRecMain type vr record case tag char of Yas chil ches char b flag boolean K ALIGN integer end var Xi YE procedure VarRec var d vr external c begin x tag a x chl a x ch2 b VarRec x writeln x ch2 end VarRecMain hostname S cc c VarRec c hostname pe calign VarRec o VarRecMain p hostname S a out Z The calign option is not needed in the previous example but may be necessary if the record contains aggregates Non Pascal Procedures When you use the x1 option in compiling Pascal code you can use the nonpascal keyword to declare that an external procedure is written in another language This keyword generally causes everything to be passed by reference The C Pascal Interface 127 lll O The C function NonPas c In the function for_c sisa pointer declared var in the procedure declaration and len is not a pointer not declared var in the procedure declaration In the function for_nonpascal sisstilla pointer though not declared var in the procedure declaration and lenisnowa pointer though not declared var The Pascal main program NonPasMain p The commands to compile and execute NonPas c and NonPasMain p 128 See this example include lt stdio h gt void for_C char s int len int i for i 0 i lt len i putchar s i putchar n void for_NonPasc
105. c command 40 qp option to pc command 40 Opath option to pc command 40 Oproduce option to pc command 40 queuing for a license 5 QUIT errors 209 R R option to pc command 41 range check on pointers 31 reading and writing scalars errors in 212 real numbers errors 206 records variant 108 125 195 redirecting input and output 11 to 13 reference parameters 94 117 128 169 replacements in the case of errors 207 Rpath option to pc command 41 running a Pascal program 9 to 13 runtime errors 217 to 220 Rw option to pc command 41 Pascal 4 0 User s Guide S S option to pc command 46 s option to pc command 46 s0 and s1 options 49 sb option to pc command 46 sbfast option to pc command 46 scalar errors 211 Selection Service XView 222 semantic errors 210 separate compilation 75 to 88 define variable 76 extern variable 76 module source files 76 program source files 76 separately compiled units 68 set types 93 110 167 179 shared libraries 24 sharing routines among units 76 to 88 variables among units 71 to 73 76 to 86 variables and routines across multiple units using define variable 82 using extern variable 86 using include files 78 84 using public var declarations 80 with x1 80 without x1 77 shortreal 154 182 sizes of types 165 slibrary directive 263 source code 40 file 38 SPARC math libraries 238 standard input file 10 output file 10 Pasc
106. cal int set Type The Pascal intset type is predefined as set of 0 127 this type takes a minimum of 16 bytes of storage A variable of procedure intsetvar_ var s intset begin s 1 3 7 8 end intsetvar_ integer 2 s 8 pointer ps s ps malloc 16 call IntSetVar s do i 5 8 write 1 s i i end do 1 format 03 1x octal word 12 write 110 001 010 binary word 8 write 876 543 210 bit nos word 8 stop The FORTRAN Pascal Interface 179 lll Co The commands to compile and hostname pe c IntSetVar p execute IntSetVar pand hostname S 77 IntSetVar o IntSetVarmain f lpfc lpc IntSetVarmain f The IntSetVarmain f output of this example depends MAIN en hostnames a out macia 0 octal word 5 0 octal word 6 O octal word 7 612 octal word 8 110 001 010 binary word 8 876 543 210 bit nos word 8 Value Parameters In general Pascal passes value parameters on the stack Simple Types without the x1 Option Without the x1 option simple types match 180 Pascal 4 0 User s Guide 8 See the following example The Pascal procedure procedure simval_ t f boolean c char i integer SimVal p t f c i r ands r real s integerl6 var reply integer are value parameters begin reply 0 If nth arg is ok set nth octal digit to one if t then reply
107. cannot be dereferenced in assignment Error Messages 289 290 24300 Improper use of the DEFINE statement 24310 End matched lt keyword gt on line lt number gt 24320 Inserted keyword end matching begin record class on line lt number gt 25010 packlunpack elements of a and z must have the same type 25020 component types of formal and actual arrays are not conformable 25030 Type of function lt name gt line lt number gt 25040 Case label type clashed with case selector expression type 25050 Type clash initializer must be a pointer 25060 Type clash type of initializer does not match type of array 25070 Type clash Integer is incompatible with real 25080 Type clash Initializer out of range 25090 Type clash real is incompatible with integer 25100 This resulted because you used which always returns real rather 25110 than div which divides integers and returns integers 25120 Type clash non identical scalar types 25130 Type clash unequal length strings 25140 Type clash varying char and unknown Pascal 4 0 User s Guide Ss lll 25150 Type clash packed and unpacked set 25160 Type clash files not allowed in this context 25170 Type clash non identical lt class gt types 25180 Type clash lt type gt s with file components not allowed in this context 25190 Type clash lt type gt is incompatible with lt type gt 25200 T
108. chable statement Unrecoverable syntax error QUIT Too many syntax errors QUIT Input line too long QUIT Unrecognizable statement Include syntax error expected or not found Absurdly deep include nesting QUIT Too many levels of include nesting QUIT Bad arbitrary base integer Bad base lt number gt number lt number gt Digits required after decimal point Digits required before decimal point Digits required in exponent Space required between number and word symbol Character string delimiter is Unmatched for string Null string not allowed Invalid preprocessed fil probably renamed as Compile the original p file with sb again Module nam xpected after keyword MODUL E Identifiers after module name ignored Error Messages 281 282 19030 Missing program statement 19040 Input is used but not defined in the program statement 19050 Output is used but not defined in the program statement 19060 Program parameter lt identifier gt is repeated N 0010 Left operand of lt operator gt must be integer real or set not lt type gt 20020 Right operand of lt operator gt must be integer real or set not lt type gt 20030 Cannot mix sets with integers and reals as operands of lt type gt N 0040 Operands of lt operator gt must be Boolean or Integer N 0050 Left operand of must be integer or real not lt type gt 20060 Right oper
109. cial case 04 g The combination 04 g turns off inlining that you usually get with 04 The H option instructs pc to compile code to perform range checking on pointers into the heap This option is implicitly turned on by the v0 and v1 options Solaris 2 x only The hname option names a shared dynamic library and provides a way to have versions of a shared dynamic library This is a loader option passed to 1d In general the name after h should be exactly the same as the one after o A space between the h and name is optional The compile time loader assigns the specified name to the shared dynamic library you are creating It records the name in the library file as the intrinsic name of the library If there is no hname option then no intrinsic name is recorded in the library file The Pascal Compiler 31 al Every executable file has a list of needed shared library files When the runtime linker links the library into an executable file the linker copies the intrinsic name from the library into that list of needed shared library files If there is no intrinsic name of a shared library then the linker copies the path of the shared library file instead helpor flags The help or flags option lists and summarizes all available options Ipathname i name keeptmp The I option gives the preprocessor additional places to look for include and include files For example hostname pe I
110. cmommmm mm 137 Sample ercer ae e A na bes 137 Compatibility of Types for C and Pascal 138 C Name Encoding cee pupa e ARANA 138 Procedure Calls C Pascal oooooooooommomommo o 138 Arguments Passed by Referente ia sc lt se eed u sees 139 Arguments Passed by Valt iawi00 vas ctv uvevieuesven 150 Function Return Valuesiccsiakih lt sss ose vee ea 152 Procedure Calls Pascal C rateros 155 Arguments Passed by Reference ooooooooooooo oo 155 Arguments Passed by Value 00c0deeaee Ve ca eae 157 Function Return Values o oo oo oooooomo omo 159 Global Variables in C and Pascal ooooooocmoomo o o 161 Pascal Pile Pointers to Citi rra dd rr rrene 162 8 The FORTRAN Pascal Interface o oooooomomomomo o 163 Compiler Mixed Language PrograMS oooooooooooo mo 163 Compatibility of Types for FORTRAN and Pascal 164 Precautions with Compatible Types 165 Incompatibilities o rn 166 Pascal 4 0 User s Guide General Parameter Passing in FORTRAN and Pascal 167 Procedure Calls FORTRAN Paseal coords 168 Variable Parameters na n pia dai 168 Value Parameters o ahah tht 1A eres aes 180 a A toes ee eee eem eeeses 183 Function Return Values iscioy rover vertida 184 Procedure Calls Pascal FORTRAN oooooomoo ooo 185 Variable Parameters cirio osivs dd 186 Value Parameters pes a ANNA 197 POUNCS 2 e ERA e raw a
111. compiler 217 parameter passing C and Pascal 93 C and Pascal 152 FORTRAN and Pascal 167 parameters as pointers to procedures with C 131 passed by address 94 168 186 197 passed by reference 94 168 186 197 passed by reference between C and Pascal 117 to 128 passed by value between Pascal and C 129 to 130 between Pascal and C 152 between Pascal and FORTRAN 180 197 to 202 value conformantarray 101 114 123 193 value conformant array passed between Pascal and FORTRAN 182 var 95 117 to 128 168 186 to 197 Pascal program how to compile 8 13 how to list 33 how to run 9 to 13 how to write 7 pc command 2 7 8 11 17 to 66 a option 24 B option 24 b option 25 bsdmalloc option 25 C option 25 c option 26 calign option 26 cg89 option 26 cg92 option 26 cond option 27 249 config option 27 246 252 256 D option 27 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 option 29 ftrap t option 30 G option 30 G option 30 g option 31 H option 31 49 help option 32 hname option 31 I option 32 i option 32 keeptmp option 32 Kpic and KPIC options 39 L option 33 1 option 33 261 Ldirectory option 33 libmieee option 34 libmil option 34 list of options 23 to 66 1lib option 34 misalign option 34 mt option 34 native option 35
112. create nil FRAME 0 set_FRAME LABEL base_frame frame_label set_FRAME_SHOW_FOOTER base_frame TRUE base_panel xv_create base_frame PANEL 0 menu xv_create nil MENU 0 set_MENU_STRINGS_3 menu optionl option2 option3 set_MENU_NOTIFY_PROC menu addr menu_proc button xv_create base_panel PANEL_BUTTON 0 set_PANEL_ LABEL WIDTH button 200 set_PANEL_LABEL_STRING button button_label set_PANEL_ITEM MENU button menu window_main_loop base_frame end menu_demo To compile menu_demo p and link in the necessary libraries use the following command line hostname pe menu_demo p Ipascal_xview_include path Lpascal_xview_include_path lpxview lxview lolgx 1X11 Now run the executable file hostname S a out 232 Pascal 4 0 User s Guide Math Libraries 1 This chapter describes how to use the 1ibm and libsunmath functions in Pascal programs The math libraries are always accessible from a Pascal program because the Pascal compiler driver pc calls 1d the linker and loader with the 1sunmath 1m options If you compile Pascal program with the v option it prints the command line used to call each of the compilation passes For convenience Pascal supports special Pascal header files math_p h and sunmath_p h which contain prototypes of math functions procedures and some useful c
113. cts between threads so that Pascal library routines can be safely used in a multiprocessing environment The MT safe library for Pascal is called 1ibpc_mt On a single processor system the code that is generated with this option runs more slowly the degradation in performance is usually insignificant however Refer to the Multithreaded Programming Guide in the Solaris documentation for more information Pascal 4 0 User s Guide Qo lll native nocx nolib The native option causes pc to generate code for the best floating point hardware available on the machine you are compiling on The fast macro includes native in its expansion Solaris 2 x only This option is a synonym for xtarget native Solaris 1 x only The nocx option makes the output executable file about 128K bytes smaller by not linking with the 1cx option However the runtime performance and accuracy of binary decimal base conversion is somewhat compromised The nolib option instructs the compiler not to link any libraries by default that is no 1 options are passed to 1d Normally the pc driver passes 1c to 1d When you use nolib pass all 1 options yourself For example the following command links 1ibm statically and the other libraries dynamically hostname pe nolib Bstatic lm Bdynamic lc test p nolibmil noqueue The nolibmil option instructs the compiler to reset fast so that it does not include inlin
114. cute ChrCAVal pand ChrCAValMain cwith calign hostname pe c calign ChrCAVal p hostnames cc ChrCAVal o ChrCAValMain c lpc hostnames a out This is a string Function Return Values The Pascal function RetReal p The C main program RetRealMain c Function return values match types the same as with parameters and they pass in much the same way Simple Types The simple types pass in a straightforward way as follows function RetReal x real real begin RetReal x 1 0 end RetReal include lt stdio h gt extern double RetReal double int main void double r s r 2 0 sS RetReal r printf Sf n s The C Pascal Interface 115 lll O The commands to compile and hostname pe c RetReal p execute RetReal pand hostname ca RetReal o RetRealMain c RetRealMain c hostname a out 3 000000 Input and Output The Pascal procedure 10 p The C main program TOMain c 116 If your C main program calls a Pascal procedure that does I O then include the following code in the C main program before you call the Pascal procedure _ PCO_ PCSTART Also in the C main program just before exit add the following line PCO __PCEXIT See this example procedure IO begin writeln Hello Pascal and St end Petersburg include lt stdio h gt extern void IO int main void
115. d operation Division by zero Overflow Underflow writeln log 1 1 Inexact FlAction clear FlMode exception Flin all writeln ieee_flags FlAction FlMode Flin F10ut Math Libraries 243 11 244 Pascal 4 0 User s Guide Pascal Preprocessor A This appendix describes the preprocessors cpp 1 and cppas CPP cpp 1 is the C language preprocessor Pascal runs your source program through cpp 1 when you compile it without the x1 option For a complete description of cpp 1 see the Solaris documentation cppas The cppas preprocessor handles the Pascal conditional variables and compiler directives You call cppas using the x1 option Conditional Variables A conditional variable is defined when it appears in a bvar directive otherwise it is undefined In addition we predefine _ sun __SVR4 sparc _ sparc ___SUNPRO_PC 0x400 unix _ unix sun These variables are not predefined when you use s0 s1 VO or V1 245 246 A defined conditional variable is enabled t rue when it appears in either the Senable directive or in the config option otherwise it is disabled false as in Svar one two Senable two The following section describes var and tenable Programs that contain conditional variables must be compiled with the x1 option Compiler Directives A directive indicates some action for the compiler to take You can use a di
116. d the file includefile and copy it into the stream before continuing 67 68 The actual includefile looks like this begin writeln Hello world end In this example the include file contains the entire program In reality an include file probably contains a set of variable or procedure declarations include files are often used when a set of declarations needs to be shared among a number of programs However suppose your program is very large and takes a long time to compile Using include files may make editing more convenient but when you make a change in one part of your program you still must recompile the entire program As another example suppose you want to be able to share compiled code with other people but for reasons of security or convenience do not want to share the source code Both of these problems are solved by separately compiled units generally called units A unit is a part of a program stored in its own file and linked with the rest of the program after compilation Using Program Units and Module Units There are two kinds of units Program unit This unit looks like any program It begins with a program header and contains the main program Here is an example program program_unit output procedure say_hello extern begin say_hello end Pascal 4 0 User s Guide The body of the procedure say_hello is not defined in this program unit
117. d to adjust the alignment type vr record case tag char of avs chil ch2 char b flag boolean K ALIGN integer end procedure varrec_ var Rec vr begin if Rec chl a then Rec ch2 Z end VarRec p The FORTRAN Pascal Interface 177 lll Co The FORTRAN main program VarRecmain f The variable ALIGNis integer 2 and is needed to match the Pascal variant record layout The commands to compile and execute VarRec pand VarRecmain f without x1 178 structure a_var character chl ch2 end structure structure b_var character flag end structure structure c_var integer 2 ALIGN end structure structure var_part union map record a_var a_rec end map map record b_var b_rec end map map record c_var c_rec end map end union end structure structure vrnt character tag record var_part var_rec end structure record vrnt VRec VRec var_rec a_rec chl a VRec var_rec a_rec ch2 b call varrec VRec write VRec var_rec a_rec ch2 stop end hostnames pe c VarRec p hostname 77 VarRec o VarRecmain f VarRecmain f MAIN hostname S a out b Pascal 4 0 User s Guide The Pascal procedure IntSetVar p which has an intset of the elements 1 3 7 8 The FORTRAN main program IntSetVarmain f Pascal Set Type The Pascal set type is incompatible with FORTRAN Pas
118. defined file variable input is equivalent to the operating system standard input file stdin Similarly the file variable output is equivalent to the standard output file stdout Following is a Pascal program that copies input to output Use an editor to type the code on your system and store it in a file called copy p program copy input output This program copies input to output var cas char begin while not eof do begin while not eoln do begin read c write c end readln writeln end end copy Pascal 4 0 User s Guide No lll Compiling the Program Use the pc command to compile the program and store it in the executable file copy Here is the command format hostname pe o copy copy p Running the Program Because the standard files input and output default to the terminal the program simply echoes each line you type The program terminates when you type the end of file Control d character at the beginning of a line Try it hostname copy hello are you listening hello are you listening goodbye I must go now goodbye I must go now Control d Redirecting I O To write the output to a file instead of to the terminal use the redirection operator gt followed by a file name For instance to write to a file called data enter the following hostname copy gt data hello are you listening goodbye I must go now Cont rol d Pa
119. different languages 87 define statement 27 define declaration 83 Index variable 76 define variable 82 diagnostics format of 210 digits in real numbers 206 directives See compiler directives dn option to pc command 28 documentation xxii to xxiii DOMAIN Pascal 27 dryrun option to pc command 28 dy option to pc command 28 E else directive 250 elseif directive 251 elseifdef directive 252 enable directive 246 254 endif directive 255 end of file errors 209 enumerated types 92 166 equivalence of types errors 214 error directive 255 error recovery 207 errors 205 to 220 automatic replacement 207 from incompatible types 210 from uninitialized variables 216 from unreachable statements 215 from unused items 216 illegal characters 205 in constructs 208 in ends of program files 209 in expressions 212 in function and procedure types 211 in goto statement 216 in identifiers 208 in reading and writing scalars 212 in real numbers 206 in scalars 211 in semantics 210 in strings 206 in symbols 208 in syntax 205 299 in type equivalence 214 out of memory 217 runtime 217 to 220 exception handling function in math libraries 240 executable file 2 9 11 18 46 default 9 17 how to rename 9 execution profile 39 Sexit directive 256 expression diagnostics 212 extended language features 56 extern option 86 88 variable 76 external option See extern option F
120. e following example uses a single dimension array void IntCA int a int lb int ub int k for k 0 k lt ub 1b k a k 4 program IntCAMain output var s array 1 3 of integer i integer procedure IntCA var a array lb ub integer of integer external c begin IntCA s for i write s writeln end IntCAMain 1 to 3 do 11 The C Pascal Interface 123 lll O The commands to compile and hostname ce c IntCA c execute IntCA c and hostname pe calign IntCA o IntCAMain p IntCAMain p hostname a out 4 4 4 The calign option is not needed for this example but may be necessary if the array parameter is an array of aggregates Records and Structures In most cases a Pascal record describes the same objects as its C structure equivalent provided that the components have compatible types and are declared in the same order For more information see Compatibility of Types for C and Pascal on page 90 Records that contain aggregates may differ because aggregates in C and Pascal sometimes have different sizes and alignments If you compile the Pascal code with the calign option the differences are eliminated A Pascal record of an integer and a character string matches a C structure of an integer and an array of char values as follows The C function StruChr c include lt string h gt struct TVarLenStr int nbytes char a 26
121. e templates Use this option after the fast option as in hostname pe fast nolibmil myprog p The noqueue option instructs the compiler not to queue this compilation if a license is not available Under normal circumstances if no license is available the compiler waits until one becomes available With this option the compiler returns immediately The Pascal Compiler 35 36 notrace O level The notrace option disables runtime traceback It is only effective when compiling the main program The 0 option instructs the compiler to run the compiled program through the object code optimizer The 0 option also calls the P option which ensures boolean expressions are only evaluated as much as needed to determine the result This process causes an increase in compile time in exchange for a decrease in compiled code size and execution time There are four levels of optimization You indicate the level by specifying a digit from 1 to 4 after the 0 option If you leave out the digit the optimization level defaults to 02 The level numbers are interpreted as follows 0 This is the most likely level of optimization to give fastest performance for most reasonable applications The default is 02 01 x01 This is the minimum amount of optimization peephole and is postpass assembly level Do not use 01 unless 02 and 03 result in excessive compilation time or shortage of swap space 02 x02 This is the basic
122. eature 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 2 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
123. ecause they are received directly by pc0 when they are used in program text while the compiler driver gives them to other compiler passes when they are given on the command line If you want to set them on the command line and also want them to have the same effect as passing them in program text use the Qopt ion command line option to pass them directly to pco You set options within comments which can be delimited by either and or and The first character in the comment must be the dollar sign must be immediately followed by an option letter Next must be either or If you want to set more than one option you can insert a comma after the first option followed by another option letter and or You can set any number of options on a single line There must be no embedded spaces You can place spaces and other ordinary comment text after the last or The new option setting takes effect at the next noncomment token The symbols plus sign and minus sign turn the option on and off respectively To understand the symbol you must know how options work in Pascal Except for b each option in Table 3 2 has a current value and a first in last out stack of up to 16 values Again except for b each option can be on or off When you begin compiling a program each stack is empty and each option has an initial current value which may be the option default value or may have been set on
124. ectories that specify the library search path used by the runtime linker If present and not null it is recorded in the output object file and passed to the runtime linker If both LD_RUN_PATH and the R option are specified the R option takes precedence The Rw option checks and issues warnings on record fields which are used but not set By default the Pascal compiler generates warnings of this kind for whole variables but not for fields This option works only for local record variables that are defined in procedures or functions not for global variables that is variables that are in the main program or in a separately compiled module This is because global variables may appear to be initialized not in the main program itself but in some procedure or function that is compiled separately which is subsequently linked to the executable program This option is suppressed when the Z option is on See Z on page 66 In this case all local variables and their components are initialized by zero values When this option is on the compiler performs a full analysis as far as possible at compile time of how record fields are assigned and used Warnings contain full access constructs for fields which are used but not set for example VALL EZA F3 The Pascal Compiler 41 The compiler issues warnings at the end of the procedure where the record variables are defined that is when some of the fields are definitely not s
125. en writeln Two is defined as b 2 selseif S config Ssthen writeln Nothing is defined Sendif writeln End program end config_example The output when you compile hostname pe xl config p config p without the hostnames a out config option Begin program End program The output when you define the hostname pe xl config one config p variable one hostname S a out Begin program One is defined as 32767 End program 248 Pascal 4 0 User s Guide jb lll The output when you define two The output when you define foo hostname pe xl config two config p hostname a out Begin program Two is defined as 32768 End program hostname pe xl config foo config p Fri Mar 3 15 22 1995 config p Error CONFIG command argument foo was never declared Compilation failed The debug Directive The Sdebug directive instructs pc to compile this line of code when you use the cond compiler directive Syntax debug Comments The debug directive works in conjunction with the cond compiler option cond causes pc to compile the lines in your program that begin with debug Without cond pc treats lines with debug as comments Pascal Preprocessor 249 lll aN The Pascal program debug p The output when you compile debug p withoutthe cond option The output when you use cond 250 Example program debug_example output This program
126. enable two begin Sif one Sthen a maxint writeln One is defined as a 2 Sendif Sif two Sthen b minint writeln Two is defined as b 2 Sendif nd enable_example hostnames pe xl enable p hostname S a out Two is defined as 32768 The Sendif Directive The Sendi f directive indicates the end of a 3if or ifdef directive See the sections on if and ifdef for more information on this directive The Serror Directive The Serror directive causes the compiler to print a string on the standard output and treat it as an error Pascal Preprocessor 255 lll aN The Pascal program error p error p produces this error if you compile it without the config sparc option 256 Syntax Serror string Comments pc does not produce an object file Example program error_example output This program demonstrates the use of th error compiler directive Svar arch begin Sif arch Sthen writeln This is a SPARC computer selse Serror Unknown architecture Sendif end error_example hostnames pe xl error p Tue Feb 28 17 10 1995 error p Line 12 error Unknown architecture E i Unknown architecture Compilation failed The Sexit Directive The Sexit directive instructs the compiler to stop processing the current Pascal source file Syntax Sexit Pascal 4 0 User s Guide A The Pascal
127. ename gt lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt exceeded lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt Bad Bad Bad Bad Bad data data data data data found found found found found on on on on on Cannot close file Cou Cou Cou Cou Cou Cou ld no ld not ld not ld no ld no ld no File name numerated read integer read real read string read varying of char read create file open file remove file reset file seek file write to file too long maximum of lt number gt exceeded File table overflow maximum of lt number gt Line limit exceeded Non positive format widths are non standard Overflow on integer read Tried to read past end of file eoln is undefined when eof is true Argument lt number gt is out of the domain of atan Pascal 4 0 User s Guide O lll Argument to argv of lt number gt is out of range Assertion lt number gt failed lt assertion message gt Cannot close null file Cannot compute cos lt number gt Cannot compute sin lt number gt Cannot open null file Floating point division by zero Enumerated type value of lt number gt is out of range on output Floating point operand is signali
128. ence couvrant aussi les licenci s de Sun qui mettent en place OPEN LOOK GUIs et qui en outre se conforment aux licences crites de Sun Le systeme X Window est un produit du X Consortium Inc CETTE PUBLICATION EST FOURNIE EN L ETAT SANS GARANTIE D AUCUNE SORTE NI EXPRESSE NI IMPLICITE Y COMPRIS ET SANS QUE CETTE LISTE NE SOIT LIMITATIVE DES GARANTIES CONCERNANT LA VALEUR MARCHANDE L APTITUDE DES PRODUITS A REPONDRE A UNE UTILISATION PARTICULIERE OU LE FAIT QU ILS NE SOIENT PAS CONTREFAISANTS DE PRODUITS DE TIERS CETTE PUBLICATION PEUT CONTENIR DES MENTIONS TECHNIQUES ERRONEES OU DES ERREURS TYPOGRAPHIQUES DES CHANGEMENTS SONT PERIODIQUEMENT APPORTES AUX INFORMATIONS CONTENUES AUX PRESENTES CES CHANGEMENTS SERONT INCORPORES AUX NOUVELLES EDITIONS DE LA PUBLICATION SUN MICROSYSTEMS INC PEUT REALISER DES AMELIORATIONS ET OU DES CHANGEMENTS DANS LE S PRODUIT S ET OU LE S PROGRAMME S DECRITS DANS DETTE PUBLICATION A TOUS MOMENTS
129. ence page 18 Language Preprocessor page 19 File Name Extensions Accepted By pc page 20 Option Passing on the Command Line page 21 Option Passing in the Program Text page 21 Options page 23 To identify the version number of pc when you compile your program call the compiler with the V option This option instructs the compiler to produce output that identifies the versions of all the programs used in compiling the compiler itself the code generator and so on 17 To identify the version number given an executable or object file created by the Pascal compiler use the following command hostname mcs p a out grep Pascal Sc4 0 18 Mar 1995 Pascal 4 0 Compile and Link Sequence 18 You can compile the file any p with the following command line hostname pe any p This command actually invokes the compiler driver which calls several programs or passes of the program each of which processes the program The output of each pass is the input to the next one After several passes the object file any o is created An executable file is then generated with the default name a out Finally the file any o is removed pc calls cpp the C preprocessor or cppas the preprocessor used when you use the x1 option e pcO the Pascal front end The global optimizer if you use the O option cg the code generator which generates the relocatable object file pc3 which checks for conflicts in symbol name
130. ents after sthen If expression is false pc skips over Sthen Sifdef Determines whether or not you previously defined a conditional variable in a Svar directive include Inserts the lines from the specified file into the input stream list Enables a listing of the program nolist Disables the program listing slibrary Inserts the lines from the specified file into the input stream Same as Sinclude Svar Defines conditional variables Swarning Prints a warning string on the standard output The rest of this appendix contains detailed descriptions and examples of each directive The config Directive The config directive is a predefined conditional variable with a value of either true or false Syntax sconfig Comments config is true when you compile your program with the config option otherwise config is false Use Sconfiginan if ifdef telseif or selseifdef directive to catch any undefined values specified with config Do not define config in the svar directive Pascal Preprocessor 247 lll aN Example The Pascal program program config_example output config p which defines the conditional variables one and This program demonstrates the use of th two config compiler directive var a integer maxint b integer minint Svar one two begin writeln Begin program Sif one then writeln One is defined as a 2 Selseif two th
131. er procedure say_hello external begin for x 1 to 5 do say_hello end Here is a module unit that declares a variable with the same name module module_unit3 var x integer procedure say_hello begin writeln Hello world for the x time end Pascal 4 0 User s Guide By default both definitions of variable x are public Thus when you compile and link the program and module units references to x refer to the same variable as follows Hello Hello Hello Hello Hello world world world world world for for for for for the the the the the Osuna hostname pc program_unit3 p module _unit3 p program_unit p module_unit p Linking hostname S a out time time time time time If you compile the program giving the x1 option the variables are private by default as follows Hello Hello Hello Hello Hello world world world world world hostnames pe xl program_unit p module_unit p Linking hostname S a out for for for for for program_unit p module_unit p the the the the the O OOOO time time time time time You can get the same effect by explicitly declaring the variable in a private var section Similarly when you use x1 you can create public variables by declaring them in a public var section As with routine declarations it is often a good idea to declare
132. ernal in shrvar_prog p Also proc must also be defined as public in shrvar_mod p which is the default Using include Files to Share Variables and Routines The include file contains the declarations for the program Placing all program declarations in a single file makes your program more consistent and easier to maintain To use this feature place the number sign character in the first position of a line immediately followed by the word include and then a file name enclosed in angle brackets lt and gt or double quotation marks The different enclosures lt gt and affect the search order for files The syntax for the include directive is determined by cpp 1 When the compiler encounters the include in the input it inserts the lines from the included file into the input stream Pascal 4 0 User s Guide nN lll The program unit inc_prog p which includes the file include h The module unit inc_mod p which also includes the file include h The include file include h The commands to compile and execute inc_prog pand inc_mod p program inc_prog include include h begin program body global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end inc_prog module inc_mod include include h procedure proc begin writeln From PROC global global global 1 end proc
133. es In most cases a Pascal record describes the same objects as its FORTRAN structure equivalent provided that the components have compatible types and are declared in the same order The compatibility of the types depends mostly on size and alignment For more information see Compatibility of Types for FORTRAN and Pascal on page 164 The FORTRAN Pascal Interface 175 111 Co A Pascal record of an integer and a character string matches a FORTRAN structure of the same Consider these examples The Pascal procedure type StruChr p lenstr record nbytes integer chrstr array 0 25 of char end procedure struchr_ var v lenstr begin v chrstr oyvay v nbytes 5 end struchr_ The FORTRAN main program structure VarLenStr StruChrmain f integer nbytes character a 25 end structure record VarLenStr vls character s25 25 vis nbytes 0 Call StruChr vls s25 1 5 vls a l vls nbytes write 1 525 1 format s25 A stop end The commands to compile and hostname pe c StruChr p execute Struchr p and hostname 77 StruChr o StruChrmain f lpfc lpc StruChrmain f StruChrmain f MAIN hostname a out s25 oyvay 176 Pascal 4 0 User s Guide Co lll The Pascal procedure VarRec p Variant Records FORTRAN equivalents of variant records can sometimes be constructed although there is some variation with architecture and sometimes you nee
134. escendants of Drawable Object At runtime the object that receives the method draws itself using its class implementation of the Draw method To write XView applications in Pascal you use special libraries modules files object handles and standard procedures The XView Toolkit 223 Compiling with Libraries Most XView procedures you call are in the libraries pxview xview and X11 To compile an XView program link the libraries in order For example hostname pe my_pascal p lpxview lxview lolgx 1X11 Header Files The header files define the necessary data types constants and external procedures necessary to write programs using the XView interface with Pascal Names The names of the header file are the same as the XView C language header files with the h extension changed to _p h For example the Pascal header file corresponding to the XView file panel h is named panel_p h Other header files are canvas_p h text_p h and so on In addition to the header files corresponding to the XView headers there is an another one stddefs_p h This file defines some basic types that are used by most of the other Pascal XView header files and is included by the header files that need it Usage To use header files with Pascal put in include lines for any other header files you need Attribute Procedures Each class of objects has its own set of attributes Each attribute has a predefined default value For examp
135. et However no warnings are issued if fields are used in the source before they are initialized as the control flow may be different In some cases it is not possible to determine at compile time whether the fields have actually been initialized For example For the array variable v whose elements are records if any assignment of the kind V i X or V i F Y occurs the compiler considers the corresponding fields of V i for all values of i to be initialized If sucha field is used but not set it is denoted as V F in the warning message e All formal parameters are assumed to be initialized Consequently the compiler does not perform any checking for these component fields With the Rw option the compiler takes into account built in procedures which initialize their argument variables for example reset f for the file buffer variable and its components rewrite f does not initialize The compiler also examines field handling inside WITH statements Use the Rw option to check the use of unsafe variant records such as the assignment of a variant to a field or the use of another field from a parallel variant These practices may result in runtime errors which are hard to find Note The Rw option requires extra compile time and is therefore recommended for use in debugging only Pascal 4 0 User s Guide The Pascal main program r p record and array of records The commands
136. fault hostname pe 1 rmc p The following command causes the generated object file to be named rmc instead of the default a out hostnames pe o rme rmc p Option Passing in the Program Text Some options can be passed to the compiler in program text as well as on the command line With this facility you can use different option values for different parts of a program Here are four examples of how options can be passed in program text SP H I 1 L n Table 3 2 shows the options that can be passed in program text Table 3 2 Options That Can Be Passed in Program Text Option Description b Uses buffering of the file output Cc Uses runtime checks same as t calign Uses C data formats H Uses check heap pointers 1 Makes a listing L Maps identifiers and keywords to lowercase p Uses statement limit counting different from command line p See stlimit in the Pascal 4 0 Reference Manual The Pascal Compiler ral 22 Table 3 2 Options That Can Be Passed in Program Text Continued Option Description P Uses partial evaluation of boolean expressions E Uses runtime checks same as C but different from the command line th u Trims to 72 character line not usable on command line w Prints warning diagnostics The options p and t are different when they are used within program text and when they are used on the command line b
137. g n OK end SimVal hostname 77 c SimVal f SimVal f simval hostnames pc SimVal o SimValmain p lpfc 1F77 hostname S a out args 111111 If nth digit 1 arg n OK The FORTRAN Pascal Interface 199 111 Co Pointers Pointers are easy to pass as shown in the following example The FORTRAN subroutine subroutine PassPtr iPtr dPtr PassPtr f Inthe FORTRAN integer subroutine the name is double precision d converted to lowercase ad pointer iPtr i dPtr d Uppsercase is ignored Bo 9 da 9 9 return end The Pascal main program program PassPtrmain PassPtrmain p Inthe Pascal program where it calls type the FORTRAN subroutine the PtrInt integer name must be in lowercase pPtrReal real var i integer 0 r real 0 0 iP Ptrint rP PtrReal procedure passptr var xiP PtriInt var xrP PtrReal external fortran begin iP addr i rP addr r passptr iP rP writeln i 2 r 4 1 end PassPtrmain 200 Pascal 4 0 User s Guide The commands to compile and execute PassPtr f and PassPtrmain p hostname S 77 c PassPtr f PassPtr f passptr hostnames pc PassPtr o PassPtrmain p lpfc 1F77 hostname S a out 9 9 9 Function Return Values The FORTRAN function RetReal f The Pascal main program RetRealmain p Function return values match types the same as with parameters a
138. g option the traceback also reports the arguments the line number and the file name of each routine Pascal Programs de lll No Try compiling SegViol p with g hostname pe g SegViol p hostname s a out a out terminated by signal 11 segmentation violation Traceback being written to a out trace Abort core dumped hostname S more a out trace Stacktrace of a out Program terminated due to segmentation violation 3 __PCO__sigdie 0xb Oxefffedf0 Oxefffec30 0x0 0x1 0x0 at 0x12128 Called from signal handler with signal 11 SIGSEGV 4 ErrorInHere line 12 in SegViol p 5 Call2 line 18 in SegViol p 6 7 Cal11 line 21 in SegViol p 7 program line 25 in SegViol p detaching from process 17285 The program prints the ASCII values of character variables If you compile some modules with g and others without the line numbers may not be accurate for all the routines 16 Pascal 4 0 User s Guide pc Version Number Oy lil The Pascal Compiler The name of the Pascal compiler is pc If you give pc a file name as an argument and the file name ends with p or pas pc compiles the file and leaves the result in an executable file called a out by default The syntax of this command is pc options filename This chapter contains the following sections pc Version Number page 17 Compile and Link Sequ
139. g the Program When you compile and run the program you receive output similar to the following The first line indicates the name of the offending signal in this case a segmentation violation Pascal 4 0 User s Guide No lll hostname S pc SegViol p hostname S a out a out terminated by signal 11 segmentation violation Traceback being written to a out trace Abort core dumped hostname S more a out trace Stacktrace of a out Program terminated due to segmentation violation 3 __PCO__sigdie Oxb Oxefffedf0 Oxefffec30 0x0 4 ErrorInHere at 0Oxll5ec 5 Cal12 0xefffefc8 Oxefffefa8 Oxefffef88 0x0 6 Cal111 0x25400 0x25800 0x25b80 0x25b80 0x3 7 program 0x1 Oxeffff0fc 0x4 Oxef7d0000 0x2 8 main 0x1 Oxeffff0fc Oxeffff104 0x25000 0x0 detaching from process 17266 0x1 called from signal handler with signal 11 SIGSEGV 0x0 at 0x12128 Oxef 74dd58 0x0 0x0 Oxef74dae8 0x0 at 0x11660 at 0x116e0 at 0x11624 at 0x116a4 In this example ErrorInHere reported the error The ErrorInHere procedure was called by Ca111 Ca112 which was in turn called by the main program Routine names such as Ca111 Ca112 indicate a nested routine If Pascal cannot find the name of a routine for example because the executable file has been stripped it prints the hex address Using the g Option If you compile the program with the
140. global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end ext_prog Pascal 4 0 User s Guide nN lll The module unit ext_mod p module ext_mod define global proc Sinclude extern h procedure proc begin writeln From PROC global global global 1 end proc The include file extern h var global extern integer procedure proc extern The commands to compile and hostname pe xl ext_prog p ext_mod p execute ext_prog p and ext_prog p ext_mod p ext_mod p Linking hostname S a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 Sharing Declarations in Multiple Units Using extern and external directives for procedure and function declarations you can optionally specify the source language of a separately compiled procedure or function For example extern fortran directs the compiler to generate calling sequences compatible with the FORTRAN compiler from SunSoft Then external c directs the compiler to generate calling sequences compatible with SunSoft C compiler Separate Compilation 87 88 For routines declared extern fortran or external fortran the changes in the calling sequence are as follows For value parameters the compiler creates a copy of the actual argument value in the caller s environment and passes a pointer to the temporary variable on the st
141. good performance on the V8 architecture but without quad precision floating point instructions Example SPARCstation 10 Limit the instruction set to the V8plus version of the V9 architecture By definition V8plus or V8 means the V9 architectue except Without the quad precision floating point instructions Limited to the 32 bit subset defined by the V8 specification Without the VIS instructions This option uses the best instruction set for good performance on the V9 architecture In V8 a system with the 64 bit registers of V9 runs in 32 bit addressing mode but the upper 32 bits of the i and registers must not affect program results Example Any machine based on UltraSPARC chip architecture Use of this option also causes the o file to be marked as a Sun specific V8 binary such files will not run ona v7 or v8 machine v8plusa Limit the instruction set to the V8plusa version of the V9 architecture By defintion V8plusa means the V8plus arcitecture plus The UltraSPARC specific instructions The VIS instructions This option uses the best instruction set for good performance on the UltraSPARC architecture but limited to the 32 bit subset defined by the V8 specification Example Any machine based on UltraSPARC chip architecture Use of this option also causes the o file to be marked as a Sun specific V8 binary such files will not run ona v7 or v8 machine Pascal 4 0 User s Guide Oy lll xc
142. gram RetShortRealMain cc The commands to compile and execute RetShortReal p and RetRealMain cc The Pascal function I0 p 154 Type shortreal function RetShortReal r shortreal shortreal begin RetShortReal r 1 0 end include lt stdio h gt include lt math h gt extern C float RetShortReal float int main void float Er 53 r 2 0 s RetShortReal r printf 8 6f An s hostnames pc c RetShortReal p hostnames CC RetShortReal o RetShortRealMain cc lpc hostnames a out 3 000000 Input and Output procedure IO begin writeln Hello Pascal amp St Petersburg end Pascal 4 0 User s Guide N lll The C main program include lt stdio h gt TOMain cc extern C void IO int main void IO 0 printf Hello C An The commands to compile and hostname pe c IO p execute IO0 p and IOMain cc hostname CC IO o IOMain cc lpc hostname a out Hello Pascal amp St Petersburg Hello C Procedure Calls Pascal C A Pascal main program can also call C functions The following examples show you how to pass simple types and arguments and include the commands that are used to compile and execute the final programs Arguments Passed by Reference Pascal arguments can be passed by reference Here we discuss how they work with C The C 4 Pascal Interface 155 lll
143. gs of Characters The FORTRAN Pascal Interface The alfa and string types pass simply varying strings are a little tricky All pass by reference 187 lll Co The FORTRAN subroutine StrVar f The Pascal main program StrVarmain p 188 subroutine StrVar s10 s80 vls character s10 10 s80 80 structure VarLenStr integer nbytes character a 25 end structure record VarLenStr vls character ax 10 sx 80 vx 5 data ax abcdefghij amp sx abcdefghijklmnopaqrstuvwxyz amp vx oyvay s10 1 10 ax 1 10 s80 1 80 sx 1 80 vis a 1 5 vx 1 5 vis nbytes 5 return end program StrVarmain output type varstr varying 25 of char var a alfa s string vi Varstr procedure strvar var xa alfa var xs string var xv varstr external fortran begin strvar a s v writeln a writeln s writeln v writeln length v length v 2 end StrVarmain Pascal 4 0 User s Guide Co lll The commands to compile and execute StrVar f and StrVarmain p hostnames 77 c StrVar f StrVar f strvar hostnames pe StrVar o StrVarmain p lpfc 1F77 hostname a out abcdefghij abcdefghijklmnopqrstuvwxyz oyvay length v 5 Character Dummy Arguments When you call FORTRAN 77 routines with character dummy arguments from Pascal programs that is routines in which string arguments are specified as character in
144. h Pascal generally passes all value parameters on the stack the exception is value conformant array parameters which are handled by creating a copy in the caller environment and passing a pointer to the copy In addition the bounds of the array must be passed See Conformant Arrays on page 173 This example is the same as the one in the earlier section except that the var prefix is deleted Pascal 4 0 User s Guide Pascal procedure ChrCAx p The FORTRAN main program ChrCAmain f The commands to compile and execute ChrCAx p and ChrCAmain f Pointers The Pascal procedure PassPtr p Inthe Pascal procedure statement the name must be all in lowercase with a trailing underscore _ procedure chrca_ a array begin a 0 T a 13 o end chrca_ 1b ub integer of char character s 16 data s this is a string call ChrCA s VAL 0 write A s stop end SVAL 15 hostname S pe c ChrCAx p ChrCAmain f MAIN hostname S a out This is a string hostnames 77 ChrCAx o ChrCAmain f lpfc lpc Pointers are easy to pass as shown in the following example type PtrInt integer PtrReal real procedure passptr_ var iPtr var dPtr begin iPtr dPtr end Il w WO er X Ptrint PtrReal r The FORTRAN Pascal Interface 183 lll Co The FORTRAN main program PassPtrmain
145. he Pascal Compiler 23 24 Bbinding The a option is the old style of basic block profiling for tcov See xprofile tcov for information on the new style of profiling and the tcov 1 man page for more details Also see the manual Profiling Tools The a option inserts code to count how many times each basic block is executed It also calls a runtime recording mechanism that creates a d file for every p file at normal termination The d file accumulates execution data for the corresponding source file The tcov 1 utility can then be run on the source file to generate statistics about the program If set at compile time the TCOVDIR environment variable specifies the directory of where the d files are located If this variable is not set then the d files remain in the same directory as the f files The xprofile tcov and the a options are compatible in a single executable That is you can link a program that contains some files which have been compiled with xprofile tcov and others with a You cannot compile a single file with both options The B option specifies whether libraries for linking are static not shared indicated with Bstatic or dynamic shared indicated with Bdynamic Link editing is the set of operations necessary to build an executable program from one or more object files Static linking indicates that the results of these Operations are saved to a file Dynamic linking refers to these operations
146. he commands to compile and hostnames 77 c VarRec f execute VarRec f and VarRec f VarRecmain p without x1 varrec hostnames pc VarRec o VarRecmain p lpfc 1F77 hostnames a out b Value Parameters With external fortran on the procedure statement Pascal passes value parameters as FORTRAN expects them The FORTRAN Pascal Interface 197 lll Co Simple Types With external fortran the procedure name in the procedure statement and in the call must be in lowercase with no underscore _ The FORTRAN subroutine subroutine SimVal t f c i d s reply SimVal f logical 1 ty E character integer 4 i double precision d integer 2 s integer 4 reply reply 0 if t reply reply 1 if not f reply reply 8 if c eq z reply reply 64 if i eq 9 reply reply 512 if d eq 9 9 reply reply 4096 if s eq 9 reply reply 32768 return end 198 Pascal 4 0 User s Guide The Pascal main program SimValmain p The commands to compile and execute SimVal f and SimValmain p program SimVal output var boolean boolean char z integer 9 real 9 9 integerl6 9 QO RRA fm ct ol eh oct Y K HG u 0 0 args integer procedure simval t f boolean c char i integer r real s integerl6 var reply integer external fortran begin simval t Es Es Ey Ej S args writeln args args 6 oct If nth digit 1 ar
147. he standard list of these types is in the header files Pascal 4 0 User s Guide 10 Coding Fragment Here is an example that illustrates the style of programming with the XView interface in Pascal This program Creates a vertical scrollbar with a view length of 100 pixels Changes the view length to 200 pixels e Destroys the scrollbar var bar pi Scrollbar begin bar xv_create 0 SCROLLBAR 0 pi xv_create_l 0 SCROLLBAR attr_create_list_4s SCROLLBAR_VIEW_LENGTH 100 SCROLLBAR DIRECTION SCROLLBAR_VERTICAL set_SCROLLBAR_VIEW_ xv_destroy bar H ENGTH bar 200 In this example bar is declared to be of type Scrollbar xv_create and xv_create_1l are invoked as functions set SCROLLBAR_VIEW_LENGTH is invoked as a procedure xv_destroy is invoked as a procedure Conversion of C to Pascal Here is an example of a problem that you may encounter when converting C to Pascal It recommends some changes that you can make to work around the problem An Example The Problem Besides the six standard generic procedures there are approximately 80 other procedures plus hundreds of attributes These are all documented in the XView Programming Manual The problem is that all of the coding is in C The XView Toolkit 227 10 228 The Straightforward Part You can use the following items of
148. hecks into the object file as follows V0 Equivalent to C H L and s0 V1 Equivalent to C H L and s1 V The v verbose option prints the command line used to call each compilation pass ZW By default the compiler prints warnings about inconsistencies it finds in the input program The w option turns off the warnings To turn off warnings in a program comment use this command hostname w xa Same as a xarch a Solaris 2 x only The xarch a option limits the set of instructions the compiler may use The Pascal Compiler 49 50 a must be one of generic v7 v8 v8a v8plus v8plusa Although this option can be used alone it is part of the expansion of the xtarget option its primary use is to override a value supplied by the xtarget option This option limits the instructions generated to those of the specified architecture and allows the specified set of instructions It does not guarantee an instruction is used however under optimization it is usually used If this option is used with optimization the appropriate choice can provide good performance of the executable on the specified architecture An inappropriate choice can result in serious degradation of performance Pascal 4 0 User s Guide 3 v7 v8 and v8a are all binary compatible v8plus and v8plusa are binary compatible with each other and forward but not backward For any particular choice the generated executable can run m
149. ibility is private File Passing Between Pascal and C You can pass a file pointer from Pascal to C then have C do the I O as in The C procedure include lt stdio h gt UseFilePtr c void UseFilePtr FILE ptr Write to the file fprintf ptr 1 Passing the file descriptor n fprintf ptr 2 and writing information An fprintf ptr 3 to a file n The Pascal main program program UseFilePtrMain UseFilePtrMain p var f text cfile univ_ptr procedure UseFilePtr cf univ_ptr external c begin rewrite f myfile data Make the file cfile getfile f Get a file pointer UseFilePtr cfile Call the C function end UseFilePtrMain 134 Pascal 4 0 User s Guide The commands to compile and execute UseFilePtc cand UseFilePtrMain p hostname S cc c UseFilePtr c hostnames pe UseFilePtr o UseFilePtrMain p hostname S a out hostname cat myfile data 1 Passing the file descriptor 2 and writing information 3 to a file The C Pascal Interface 135 136 Pascal 4 0 User s Guide Sample Interface The C Pascal Interface f This chapter describes how to mix C and Pascal modules in the same program It contains the following sections Sample Interface page 137 Compatibility of Types for C and Pascal page 138 C Name Encoding page 138 Procedure Calls C Pasc
150. ibrary 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 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 Pascal 4 0 User s Guide lll Text Editors Debuggers X View Toolkit The operating system provides two main editors e Text Editor A window based text editor that runs in the OpenWindows environment Start this tool by typing textedit at the system prompt vi tThe 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 e The autoindent option provides white space at the beginning of a line e 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 e 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 f
151. ig Directive on page 247 The warning Directive The warning directive instructs pc to print a string on the standard output as a compiler warning Syntax Swarning string Comments pc produces an object file Pascal Preprocessor 263 lll aN The Pascal program warning p The output when you compile warning p without the config option 264 Example program warning_example output This program demonstrates the use of the Swarning compiler directives Svar blue begin Sif blue then writeln The color is blue else Swarning Color not defined Sendif end warning_example hostname pe xl warning p Fri Mar 3 15 03 1995 warning p Line 12 swarning Color not defined w i Architecture not defined Pascal 4 0 User s Guide Error Messages B The following is a list of the error messages produced by Pascal arranged by message number 10010 10020 10030 and at 10040 10050 10060 10070 10080 10090 10100 10110 Builtin lt function gt takes exactly lt number gt arguments Builtin lt function gt takes at least lt number gt arguments Builtin lt function gt takes at least lt number gt arguments most lt number gt Built in lt function gt cannot be passed as a parameter argv takes two arguments argv s first argument must be an integer not lt type gt argv s second argument must be a st
152. in a different way pc summarizes all incorrect uses in the same way it summarizes uses of undeclared variables Expected Symbols and Malformed Constructs The Pascal program synerr2 p Here output is misspelled and a is given a FORTRAN style variable declaration 208 If none of the corrections mentioned previously appears reasonable the error recovery routine examines the input to the left of the point of error to see if there is only one symbol that can follow this input If so the recovery prints a diagnostic which indicates that the given symbol is expected In cases where none of these corrections resolve the problems in the input the recovery may issue a diagnostic that indicates malformed input If necessary pc can then skip forward in the input to a place where analysis can continue This process may cause some errors in the missed text to be skipped See this example program synerr2_example input outpu integer a 10 begin read b for c 1 to 10 do alc b lt end synerr2_example Pascal 4 0 User s Guide O lll These are the error messages you receive when you compile synerr2 p On line 6 parentheses are used for subscripting as in FORTRAN rather than the square brackets that are used in Pascal The compiler noted that a was not defined as a procedure delimited by parentheses in Pascal Since you cannot assign values to procedure calls pc diagnosed a
153. in an increase in the size of the executables When optimizing for size use level 02 For most programs 04 is faster than 03 which is faster than 02 which is faster than 01 However in a few cases 02 may be faster than the others and 03 may be faster than 04 You can try compiling with each level to see if you have one of these rare cases If the optimizer runs out of memory it tries to recover by retrying the current procedure at a lower level of optimization then resumes subsequent procedures at the original level specified in the O command line option If you optimize at 03 or 04 with very large procedures thousands of lines of code in a single procedure the optimizer may require an unreasonable amount of memory Such cases may result in degraded machine performance You can prevent this from happening in the C shell by limiting the amount of virtual memory available to a single process To do this use the limit command see csh 1 For example to limit virtual memory to 16 megabytes hostname limit datasize 16M The Pascal Compiler 37 38 o filename This command causes the optimizer to try to recover if it reaches 16 megabytes of data space This limit cannot be greater than the machine s total available swap space and in practice should be small enough to permit normal use of the machine while a large compilation is in progress For example on a machine with 32 megabytes of swap space the c
154. ince there is no type or size checking for separate compilations However if you want to use an existing Pascal procedure that has a univ array you can do so All univ arrays that are in out in out or var parameters pass by reference var i integer begin Total 0 for i 0 to Last do Total Total V i univec_ end type VecTyp array 0 9 of integer procedure univec_ in V univ VecTyp var Last var Total integer integer integer Sum integer a 0 2 data a 7 8 9 call UniVec a 2 Sum write 13 Sum stop end Pascal 4 0 User s Guide Co lll The commands to compile and execute UniVec p and UniVecmain f hostnames pe c UniVec p hostname 77 UniVec o UniVecmain f lpfc lpc UniVecmain f MAIN hostnames a out 24 Conformant Arrays For conformant arrays with single dimension array pass upper and lower bounds placed after the declared parameter list as in function ip var x array lb ub integer of real real double precision v1 10 double precision z z ip vil SVAL 0 SVAL 9 Pascal passes the bounds by value so FORTRAN must pass them by value too One bounds pair may apply to several arrays if they are declared in the same parameter group function ip var x y array lb ub integer of real real double precision v1 10 v2 10 double precision z z ip vl v2 SVAL 0 SVAL 9
155. ine NC 3 define NR 2 extern void RealCA double NC int int int int int int main void double M NR NC int col cl c2 row rl r2 we wr cl 0 rl 0 c2 NC 1 r2 NR 1 wc sizeof M 0 0 wr c2 cl 1 wc RealCA M rl r2 wr cl c2 for row rl row lt r2 row printf n for col cl col lt c2 col printf 4 1f M row col y print n The C Pascal Interface 103 lll O The commands to compile and execute RealCA p and RealCAMain c with calign The Pascal procedure ChrCAVar p The C main program ChrCAVarMain c ForC the lower bound is always 0 104 hostname hostname hostname pc c calign RealCA p cc RealCA o RealCAMain c lpc a out OF oo 2 oo oo e If wc is the width of the smallest element as determined by sizeof then the width of the next largest element is the number of those smaller elements in the next larger element multiplied by wc width of next largest element ub lb 1 we In general 1b ub wc are the bounds and element width of the next lower dimension of the array This definition is recursive Example 3 Array of Characters procedure ChrCAVar var a array lb ub integer of char I SESS 3 o ChrCAVar include lt stdio h gt extern void ChrCAVar char int int int main void static char s this is a string ChrC
156. information as you find them in the manual with no change e The XView procedure names e The XView object names e The XView object data types except Boolean see the following section The More Complex Parts You must make the following changes Any elementary C data type used must be converted to the corresponding Pascal data type AnyC procedure that returns something must be invoked in Pascal as a function otherwise it must be invoked as a procedure e The XView type Boolean must be converted to the Pascal type boolean Table 10 1 shows you how to convert C declarations to Pascal Table 10 1 C Declarations to Pascal Declarations C Pascal int integer subrange or numeric constant unsigned unsigned subrange or numeric constant short integerl6 subrange or numeric constant unsigned short unsignedl6 subrange or nonnegative numeric constant char char or single letter string literal for special definition modules float shortreal longreal or real constant always passed as LONGREAL double real or real constant any pointer type pointer type any enum type unsigned type any struct type record type of corresponding size and layout char array of char or string literal other array types array type of corresponding size 1 Defined in stddefs_p A Pascal 4 0 User s Guide 10 Sample Tra
157. inition for a given routine but every routine must be declared in every module or program unit that usesit Program Construction and Management 69 70 You can also separate the compilation and linking or loading steps as follows hostname pe program_unit p c hostname pe module_unit p c hostname pe program_unit o module_unit o In this case you call pc on each unit with the compile only option c which produces an object file with the extension o When you use this option the compiler driver does not call the linker 1d You then call pca second time giving the names of the object files and pc calls pc3 to check for name and type conflicts before calling the linker Calling the linker or loader 1d 1 directly does not have the same effect as calling pc when you call 14 1 directly the files are linked and loaded but they are not checked for conflicts Using Units and Header Files A complex program may have many routines defined in modules Each routine must have a declaration for example procedure proc extern in each file that calls the routine The easiest way to be sure that you have a correct and consistent set of declarations is to create a header file A header file is a file that contains a set of declarations nothing else You use a header file by using an include directive to include the header file in the compilation For example here is a modified version of the program program_unit that u
158. is 2 x only cpp 1 cppas inline 1 iropt 1d 1 pcO or pc3 For example the following command passes the option R to cpp and allows recursive macros hostname pe Qoption cpp R myprog p Qpath pathname The Qpath option inserts a path name into the compilation search path hence providing an alternate path to search for each compiler component You can select this option for instance to use a different linker or assembler In the following command pc searches home pascal sparc for the compiler components and uses them if it finds them if pc does not find the specified components it uses the default components hostname pe Qpath home pascal sparc testp p Qproduce qp The Qproduce option instructs pc to produce source code of the type sourcetype which can be one of the following 9 Object file from as 1 pi Preprocessed Pascal source from cpp 1 US Assembler source This option is the same as the S option For example the following command produces the file hello s hostname pe Qproduce s hello p The qp option is the same as p option Pascal 4 0 User s Guide Oy lll Solaris 1 x only The R option instructs pc to call the assembler as 1 This option merges the data segment of the resulting program with the text segment See also xMerge Solaris 2 x only R path dir Solaris 2 x only The Rpath dir option passes a colon separated list of dir
159. is chapter introduces the XView programmer s toolkit a part of the XView application programmer s interface API It assumes you are familiar with XView windows as a user and introduces XView from a programmer s point of view For details see the XView Programming Manual by Dan Heller O Reilly amp Associates Inc 1990 The sections in this chapter are Overview page 221 Pascal Interface page 223 Conversion of C to Pascal page 227 Sample Program page 230 Note Support for the XView toolkit will not be provided in future releases of Pascal The XView API is an object oriented server based user interface toolkit for the X Window System Version 11 X11 It is designed and documented to help programmers manipulate XView windows and other XView objects This chapter focuses on using it with Pascal 221 10 222 Tools Objects This kit is a collection of functions The runtime system is based on each application having access to a server based Notifier which distributes input to the appropriate window and a Window Manager which manages overlapping windows There is also a Selection Service for exchanging data between windows in the same or different processes XView is an object oriented system XView applications create and manipulate XView objects that are associated with XView packages Objects in the same package share common properties The major objects are windows icons cur
160. is terminated Save a copy of your program then contact Sun Customer Support If you were making changes to an existing program when the problem occurred you may be able to work around the problem by determining which change caused the internal error and making a different change or error correction to your program The only other error that aborts compilation when no source errors are detected is running out of memory Most tables in Pascal with the exception of the parse stack are dynamically allocated and can grow to take up a good deal of process space In general you can get around this problem with large programs by using the separate compilation facility See Chapter 5 Separate Compilation for details If you receive an out of space message during translation of a large procedure or function or one containing a large number of string constants either break the procedure or function into smaller pieces or increase the maximum data segment size using the 1imit command of csh 1 When Pascal detects an error in a program during runtime it prints an error message and aborts the program producing a core image Following is a list of runtime errors that Pascal generates lt filename gt Attempt to read from a file open for writing lt filename gt Attempt to write to a file open for reading Error Diagnostics 217 218 lt filename gt lt filename gt lt filename gt lt filename gt lt filename gt lt fil
161. it s first argument must be a text file not lt type gt 10760 page expects one argument 10770 Argument to page must be a text file not lt type gt 10780 Assert expects one or two arguments 10790 Second argument to assert must be a string not lt type gt 10800 pack expects three arguments 10810 unpack expects three arguments 10820 Illegal transfer function argument 10830 constant argument expected Error Messages 269 270 10840 Illegal argument with format radix specification probably a comma missing 11010 have incompatible conformant array schemas 11020 sizeof conformant array is undefined 11030 Conformant arrays are not allowed at ANSI Level 0 11040 Subscripting allowed only on arrays not on lt type gt s 11050 subrange value or array subscript lt integer gt is out of range 11060 compiler takes size of array 11070 Elements of a packed array cannot be passed by reference 11080 Subscripting allowed only on arrays and varying not on lt type gt s 11090 Varying size must be a constant 11100 Size of lt identifier gt is zero 11110 Character array lower bound lt gt 1 11120 Character array upper bound of 1 11130 lt function gt requires a to be an unpacked array not lt type gt 11140 lt function gt requires z to be a packed array not lt type gt 11150 lt operation gt not allowed on arrays only allow and lt gt 11160 Packed multidimensional confo
162. kips over the then part and executes the Selseif part instead expression consists of a conditional variable and the optional boolean operators and or and not See the else listing for examples of expression Example program elseif_example output This program demonstrates the use of the Sif Sthen and elseif directives Svar blue red begin Sif blue then writeln The color is blue Selseif red then writeln The color is red Sendif nd elseif_example hostnames pe xl config blue elseif p hostname S a out The color is blue hostnames pe xl config red elseif p hostname S a out The color is red The Selseifdef Directive The elseifdef directive provides an alternative action to the ifdef directive Pascal 4 0 User s Guide sn lll The Pascal program ifdef p which first checks if birdi has been defined If not it defines it with a Svar directive If bird1 has been defined the program checks whether or not it needs to define bird2 Syntax Sifdef expression sthen selseifdef expression sthen Sendif Comments If the expression in ifdef expression sthen is false pc skips over the then part and executes the telseifdef part instead expression consists of a conditional variable and the optional boolean operators and or and not See the Selse listing for examples of expression Example program ifdef_example output
163. le 86 using include files 78 84 using public var declarations 80 without x1 77 variant records 108 125 195 vi text editor 3 V0 and V1 options to pc command 49 Ww w option to pc command 49 warning directive 263 warning diagnostic 49 Window Manager XView 222 write procedure 46 305 writing a Pascal program 7 writing scalars errors in 212 X xarch a option to pc command 49 xcache a option to pc command 53 xchip c option to pc command 54 xF option to pc command 55 xildoff option to pc command 56 xildon option to pc command 56 x1 option to pc command 56 245 xlibmopt option to pc command 57 xlicinfo licensing option 5 xlicinfo option to pc command 57 xMerge option to pc command 57 xnolibmopt option to pc command 57 xregs r option to pc command 60 xs option to pc command 61 xsafe mem option to pc command 61 xspace option to pc command 62 xtarget t option to pc command 62 XView attributes 224 data types 226 documentation 221 handles 226 header files 224 introduction 3 Notifier 222 Selection Service 222 Window Manager 222 Z Z option to pc command 66 ztext option to pc command 66 306 Pascal 4 0 User s Guide 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 prot g par un copyright et distribu avec des licences q
164. le for the class of scrollbars there is a width and a color The standard C interface to XView defines two routines xv_get and xv_set which get and set attributes of XView objects These routines take an arbitrary number and type of parameters and return various types depending on its arguments Pascal 4 0 User s Guide 10 Instead of these routines the Pascal interface to XView defines a separate routine to get and set each attribute set The routine to set an attribute is called set_attrname Each set routine is a procedure and takes as its first argument the object for which the attribute is being set The second argument is the value of the attribute get The routine to get the value of an attribute is called get_attrname Each get routine is a function and takes an XView object as the first argument It returns the value of the attribute requested For example set_WIN_SHOW frame true width get_CANVAS_WIDTH canvas These routines are defined in the header file attrgetset_p h Attribute Lists Some of the XView C routines can optionally take extra arguments that are lists of attributes and values The extra arguments vary in number and type You must pass a 0 to the last argument of these routines Since Pascal does not support variable length argument lists the Pascal definition has a single argument Instead special versions of these routines are provided which take
165. line lt number gt 21180 does not match type of lt class gt parameter lt identifier gt of lt identifier gt line lt number gt 21190 Parameter congruity error incompatible groupings 21200 Packed unpacked type conflict between parameters of lt identifier gt and lt identifier gt 21210 than formal lt class gt parameter lt identifier gt line lt number gt 21220 Conformant array parameter bound symbol table entry is NULL Pascal 4 0 User s Guide Ss lll 21230 Program parameter lt identifier gt is repeated 21240 Previous declaration for formal parameter lt identifier gt has different type 21250 Previous declaration for formal parameter lt identifier gt has different name lt identifier gt 21260 Previous declaration for procedure lt identifier gt had different number of formal parameters 21270 Formal lt class gt lt name gt cannot be qualified 21280 lt class gt lt name gt cannot be qualified 21290 Expression given lt class gt required for lt class gt parameter lt identifier gt 21300 Variable given lt class gt required for lt class gt parameter lt identifier gt 21310 Cannot take value of OUT parameter 21320 Invalid assignment to a parameter marked as IN 21330 Parameter congruity error incompatible groupings 21340 UNIV parameter lt identifier gt should be passed as a var parameter 21350 Fields which select variant
166. lows on Feb 13 13 16 20 1995 inchar p E 25190 line 6 Type clash integer is incompatible with char 25560 Type of expression clashed with type of variable in assignment In this case one error produces a two line error message If the same error occurs more than once the same explanatory diagnostic is given each time The scalar Class The only class whose meaning is not self explanatory is scalar It has a precise meaning in the Pascal standard where it refers to char integer and boolean types as well as the enumerated types For the purposes of the Pascal compiler scalar in an error message refers to a user defined enumerated type such as color in type color red green blue For integers the more precise denotation integer is used Procedure and Function Type Errors For built in procedures and functions two kinds of errors may occur If a routine is called with the wrong number of arguments a message similar to the following is displayed on Feb 13 13 21 26 1995 sin p E 10010 line 6 Builtin function SIN takes exactly 1 argument If the type of an argument is wrong you receive a message similar to the following on Feb 13 13 31 14 1995 abs p E 10180 line 8 Argument to ABS must be of type integer or real not char Error Diagnostics 211 212 Scalar Error Messages Error messages stating that scalar user defined types cannot be read from and writ
167. ls NBytes printf s10 s An s80 s An s25 S s s10 s80 s25 printf strlen s25 d An strlen s25 A hostnames pe c StrRef p hostname CC StrRef o StrRefMain cc lpc hostname a out s10 abcdefghi s80 abcdefghijklmnopgqrstuvwxyz s25 varstr strlen s25 6 The C Pascal Interface 143 lll N The Pascal procedure FixVec p The C main program FixVedMain cc The commands to compile and execute FixVec p and FixVecMain cc 144 Fixed Arrays type TVec array 0 8 of integer procedure FixVec var V TVec var Sum integer i var i integer begin Sum 0 for i 0 to 8 do Sum Sum V il end include lt stdio h gt extern C void FixVec int l int amp int main void int Sum static int a 1 2 3 4 5 6 7 8 9 FixVec a Sum printf d In Sum hostnames pe c FixVec p CC FixVec o FixVecMain cc lpc a out hostnames hostnames 45 Pascal 4 0 User s Guide E The Pascal procedure DaysOfWeek p The C main program DaysOfWeekMain cc Although it does not apply to this example arrays of aggregates in Pascal have by default a size that is a multiple of four bytes When you use the calign option to compile Pascal code that difference from C is eliminated The following example illustrates this point The string Sunday
168. mand name as in hostname man pc Pascal 4 0 User s Guide README Files The README default directory is opt SUNWspro READMEs This directory contains the following files e A Pascal 4 0 README called pascal that describes the new features software incompatibilities and software bugs e 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 Pascal 4 0 User s Guide Pascal 4 0 Reference Manual Pascal 4 0 Quick Reference Title Hard Copy On Line X X AnswerBook X X AnswerBook 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 Ans
169. me checks that verifies that Subscripts and subranges are in range The number of lines written to output does not exceed the number set by the linelimit procedure See the Pascal 4 0 Reference Manual for information on linelimit Overflow underflow and divide by zero do not exist e The assert statement is correct See the Pascal 4 0 Reference Manual for information on assert If you do not specify C most runtime checks are disabled and pc treats the assert statement as a comment and never uses calls to the linelimit procedure to halt the program However divide by zero checks are always made The v0 and V1 options implicitly turn on C The Pascal Compiler 25 26 tal gm cg89 cg92 cond The c option instructs the compiler not to call the linker 1d 1 The Pascal compiler pc leaves a o or object file for each source file Without c pc calls the linker when it finishes compilation and produces an executable file called a out by default The calign option instructs the compiler to allocate storage in records the same way as the C compiler allocates structures See the Pascal 4 0 Reference Manual for details of how data is aligned with and without calign You can use calign within a program as well as on the command line However calign only has an effect in the type and var sections of the program Any types you define when calign is on use C style alignment whenever you define vari
170. miter In this version is used for include and preprocessor directives and must be in column 1 Digits in Real Numbers Pascal requires digits in real numbers before the decimal point Thus the statements b 075 andc 05e 10 generate the following diagnostics in Pascal Mon Feb 13 10 46 44 1995 digerr p 5 b 075 18740 pS Digits required before decimal point 6 c 05e L0 e 18740 N Digits required before decimal point These constructs are also illegal as data input to variables in read statements whose arguments are variables of type real single shortreal double and longreal Pascal 4 0 User s Guide O lll Replacements Insertions and Deletions The Pascal program synerr p which uses as an exponentiation operator synerr p produces a fatal syntax error when you compile it because Pascal does not have an exponentiation operator When Pascal encounters a syntax error in the input text the compiler invokes an error recovery procedure This procedure examines the input text immediately after the point of error and uses a set of simple corrections to determine whether or not to allow the analysis to continue These corrections involve replacing an input token with a different token or inserting a token Most of these changes do not cause fatal syntax errors The exception is the insertion of or replacement with a symbol such as an identifier or a number in these cases the recove
171. mp s80 Ay MIT E USAGI Bae UE OY end Pascal 4 0 User s Guide The commands to compile and execute StrVar pand StrVarmain f The Pascal procedure FixVec p The FORTRAN main program FixVecmain f hostname pe c StrVar p hostname 77 StrVar o StrVarmain f lpfc lpc StrVarmain f MAIN hostname s a out s10 abcdefghij s80 abcdefghijklmnopgqrtstuvwxyz s25 oyvay Fixed Arrays For a fixed array parameter pass the same type and size by reference as shown in the following example type VecTyp array 0 8 of integer procedure fixvec_ var V VecTyp var Total integer var i integer begin Total 0 for i 0 to 8 do Total Total V i fixvec_ end integer Sum integer a 9 data a 1 2 3 4 5 6 7 8 9 call FixVec a Sum write 13 Sum stop end The FORTRAN Pascal Interface 171 lll Co The commands to compile and execute FixVec p and FixVecmain f The Pascal procedure UniVec p which defines a 10 element array The FORTRAN main program UniVecmain f which passes a 3 element array to the Pascal procedure written to do a 10 element array 172 hostname pe c FixVec p hostname 77 FixVec o FixVecmain f lpfc lpc hostname a out FixVecmain f MAIN 45 The univ Arrays You can pass any size array to a Pascal procedure expecting a univ array but there is no advantage in doing so s
172. n Assuming one and two are conditional variables expression can be any of the following one two one and two one or two not one not two Example See the example in the el1se listing on page 250 The ifdef Directive The ifdef directive determines whether or not you previously defined a conditional variable in a svar directive Syntax Sifdef expression sthen selseifdef expression then Sendif Pascal 4 0 User s Guide on lll The program unit include_prog p Comments expression consists of a conditional variable and the optional boolean operators and or and not See the else listing for examples of expression ifdef is especially useful for determining whether or not a conditional variable has been declared in an include file Example See the example in The elseifdef Directive The S include Directive The include directive inserts lines from the specified file in the input stream Syntax Sinclude filename Comments When cppas encounters the include directive it inserts the lines from the file name into the input stream Example program include_prog Sinclude extern h begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end include_prog Pascal Preprocessor 259 A The module unit include_mod p The include file include h The commands to compile and execute ext_prog
173. n multidimension and array of character conformant arrays follow Conformant arrays are included here only because they are a relatively standard feature there are usually more efficient and simpler ways to do the same thing Example 1 Single Dimension Array procedure IntCA var a array lb ub integer of integer begin a 1 1 a 2 2 end IntCA include lt stdio h gt extern void IntCA int int int int main void int k static int s 1 0 0 0 IntCA s 0 sizeof s 1 for k 0 k lt 3 k printf sd In s k hostname pe c calign IntCA p hostname ce IntCA o IntCAMain c lpc hostname a out 0 1 2 Pascal 4 0 User s Guide The Pascal procedure RealCA p Pascal passes low bound high bound and element width The C main program RealCAMain c Array Mhas 2 rows of 3 columns each c1 and c2 are the first and last columns r1 and r2 are the first and last rows wc is the width of a column element smallest and is equal to sizeof M 0 0 wristhe width of a row element next largest and is equal to c2 cl 1 wc Example 2 Multi Dimension Array procedure RealCA var A array rl r2 integer of array cl c2 integer of real var col row integer begin for row rl to r2 do for col cl to c2 do if row col then A row col 1 0 else A row col 0 0 end RealCA include lt stdio h gt def
174. n disables Auto Read for dbx in case you cannot keep the o files around This option passes the s option to the assembler and the linker No Auto Read This is the older way of loading symbol tables e The compiler instructs the linker to place all symbol tables for dbx in the executable file e The linker links more slowly and dbx initializes more slowly If you move the executables to another directory then to use dbx you must move the source files but you need not move the object 0 files Auto Read This is the newer and default way of loading symbol tables e The compiler distributes this information in the o files so that dbx loads the symbol table information only if and when it is needed e The linker links faster and dbx initializes faster If you move the executables to another directory then to use dbx you must move both the source files and the object 0 files xsafe mem xsb xsbfast Solaris 2 x only The xsafe mem option allows the compiler to assume no memory based traps occur This option grants permission to use the speculative load instruction on V9 machines Same as sb Same as sbfast The Pascal Compiler 61 62 xspace Solaris 2 x only The xspace option does no optimizations that increase the code size Example Do not unroll loops xtarget t Solaris 2 x only The xtarget t option specifies the target system for the instruction set and
175. n pas hostnames 77 g sun o mygrout f lpc mygrout f mygrout hostnames a out Starting Trio Jee Ending Pascal 4 0 User s Guide The FORTRAN subroutine FixVec f The Pascal main program FixVecmain p The commands to compile and execute FixVec f and FixVecmain p Fixed Arrays For a fixed array parameter pass the same type and size by reference subroutine FixVec V Sum integer Sum integer V 0 8 integer i Sum 0 do 2 i 0 8 2 Sum Sum V i return end program FixVecmain output type VecTyp array 0 8 of integer var V VecTyp 1 2 3 4 5 6 7 8 9 Sum integer procedure fixvec var XV VecTyp var XSum integer external fortran begin fixvec V Sum writeln Sum 4 end FixVecmain hostname S 77 c FixVec f FixVec f fixvec hostnames pe FixVec o FixVecmain p lpfc 1F77 hostname S a out 45 The FORTRAN Pascal Interface 191 111 Co The FORTRAN subroutine UniVec f The Pascal main program UniVecmain p 192 The univ Arrays The univ arrays that are in out in out or var parameters pass by reference subroutine UniVec V Last Sum integer V 0 2 Last Sum i Sum 0 do i 0 Last Sum Sum V i end do return end program UniVec type VecTyp array 0 9 of integer procedure univec var V univ VecTyp in Last var Sum integer external var
176. n routine that calls FORTRAN you must use the compiler options lpfc and 1F77 The 1F77 option links the FORTRAN object library 11b 77 You must specify lpfc on the command line before 1F77 For example hostnames 77 c my_fortran f hostnames pe my _fortran o my_pascal p lpfc 1F77 my_fortran f MAIN You can omit the libraries if the foreign language module does not interact with the runtime environment that is it does no I O memory allocation and so on However there is no overhead to linking to an unused library therefore always link in the appropriate runtime libraries even if you think you may not need them Compatibility of Types for FORTRAN and Pascal 164 Table 8 1 lists the default sizes and alignments of compatible types for FORTRAN and Pascal Pascal 4 0 User s Guide 8 Table 8 1 Default Sizes and Alignments of Compatible Types Pascal and FORTRAN Pascal Type FORTRAN Type Size Bytes Alignment Bytes double double precision 8 8 longreal double precision 8 8 real double precision 8 8 single real 4 4 shortreal real 4 4 integerl6 integer 2 2 2 integer32 integer 4 4 4 integer integer 4 4 4 128 127 logical 1 byte or 1 1 character boolean logical 1 byte or 1 1 character alfa character 10 10 1 char character 1 1 string character 80 80 1 varyingl n structure v 4 of char integer 4 character n end structure array array
177. nclude lt stdio h gt extern void UniVec int int int int main void int Sum static int a 7 8 9 UniVec a 2 amp Sum printf d In Sum Pascal 4 0 User s Guide o lll The commands to compile and execute UniVec p and UniVecMain c with calign hostname pe c calign UniVec p hostname cc UniVec o UniVecMain c lpc hostname s a out 24 Conformant Arrays For single dimension conformant arrays pass upper and lower bounds placed after the declared parameter list If the array is multidimensional pass element widths as well one element width for each dimension except the last one See this example function ip var x array lb ub integer of real real extern double ip double int int double v1 10 double z z ip vl 0 9 One bounds pair may apply to several arrays if they are declared in the same parameter group function ip var x y array lb ub integer of real real double v1 10 v2 10 extern double ip double z z ip vil v2 0 9 With multidimensional arrays for all dimensions but the last one pass the low bound high bound and element width The C Pascal Interface 101 lll O The Pascal procedure IntCA p Pascal passes the bounds pair The C main program IntCAMain c The commands to compile and execute IntCA p and IntCAMain cwith calign 102 Examples of single dimensio
178. nd they pass in much the same way Simple Types The simple types pass in a straightforward way as in this example double precision function retreal x retreal x 1 0 return end program retrealmain var r s real function retreal x real real external fortran begin r 2 0 s retreal r writeln r 4 1 s 4 1 retrealmain end The FORTRAN Pascal Interface 201 lll Co The commands to compile and execute RetReal f and RetRealmain p Routines as Parameters The FORTRAN subroutine PassProc f 202 hostname 77 c RetReal f RetReal f retreal hostnames pc RetReal o RetRealmain p lpfc 1F77 hostname S a out 2201 30 Type shortreal You can return a shortreal function value between Pascal and FORTRAN Pass it exactly as in the previous example with the Pascal shortreal type matching the FORTRAN real type without x1 If the passed procedure is a top level procedure write it as follows subroutine PassProc r s predr real r s external predr Call predre rr s return end Pascal 4 0 User s Guide Co lll The Pascal main program PassProcmain p The commands to compile and execute PassProc f and PassProcmain p program PassProcmain var a b real procedure passproc var u real var v real procedure p var r real var s real external fortran procedure AddOne var x real var y
179. ng Not A Number Floating point overflow Floating point underflow Inexact floating point result Integer divide by zero Integer overflow Internal error in enumerated typ Illegal argument of lt number gt to trunc read Invalid floating point operand Label of lt number gt not found in case Negative argument of lt number gt to sqrt Non positive argument of lt number gt to ln Overflow Subrange Array Subscript Error Diagnostics Error 219 220 Pointer value lt number gt out of legal range Ran out of memory Range lower bound of lt number gt out of set bounds Range upper bound of lt number gt out of set bounds Reference to an inactive file Second operand to MOD lt number gt must be greater than zero Statement count limit of lt number gt exceeded Subrange or array subscript is out of range Sun FPA not enabled Unknown SIGFPE code Unordered floating point comparison Value of lt number gt out of set bounds Varying length string index lt number gt is out of range exp lt number gt yields a result that is out of the range of reals pe ll lt number gt Bad i to pack a i z lt number gt Bad i to unpack z a i pe ll pack a i z z has lt number gt more elements than a substring outside of bounds of string unpack z a i z has lt number gt more elements than a Pascal 4 0 User s Guide Overview The X View Toolkit 10 Th
180. nslation of an XView Function to Pascal In the section Summary of Procedures and Macros in the XView Programming Manual is the following entry texsw_insert Inserts characters in buf into textsw at the current insertion point The number of characters actually inserted is returned This will equal buf_len unless there was a memory allocation failure If there was a failure it will return 0 Textsw_index textsw_insert textsw buf buf_len Textsw textsw char buf int buf_len If you translate the entry to Pascal it means e Leave the object data type Text sw as is e Since the function returns the number of characters inserted invoke it as an integer function var textsw Textsw buf array 0 3 of char buf_len integer N Textsw_index begin N textsw_insert textsw buf buf_len end The XView Toolkit 229 10 Sample Program 230 The following program xview p makes a window program hello output include stddefs_p h include attrgetset_p h var base_frame Frame base_panel Panel message Xv_panel_or_item_ptr text string begin text Hello World xv_init 0 base_frame xv_create nil FRAME 0 base_panel xv_create base_frame PANEL 0 messag xv_create panel PANEL_MESSAGE 0 set_PANEL_LABEL_STRING message text window_main_loop base_frame end
181. nt type clashed with variant case selector type 25460 Tag type is out of range 25470 Variant label type incompatible with selector type 25480 set types must be compatible in comparisons operator was lt operator gt 292 Pascal 4 0 User s Guide B 25490 lt class gt types must be identical in comparisons operator was lt operator gt 25500 Index type clashed with set component type for in 25510 Operands of are of incompatible types 25520 Type names e g lt fype gt allowed only in declarations 25530 Type name e g lt type gt found in illegal context 25540 Set types of operands of lt operator gt must be compatible 25550 expression has invalid type 25560 Type of expression clashed with type of variable in assignment 25570 Type of expression in if statement must be Boolean not lt type gt 25580 Type of transfer function does not match type of right side 25590 lt identifier gt is a lt class gt not a type as required 25600 Set type must be range or scalar not lt type gt 25610 Sets must have basetype with range lt number gt lt number gt 25620 Subrange type cannot contain a expression 25630 Scalar types must be identical in subranges 25640 Can t mix lt identifier gt s and lt identifier gt s in subranges 25650 Subrange of real is not allowed 25660 Subrange bounds must be Boolean character integer or scalar not lt type gt Error Messages 2
182. ntax Errors page 205 Compiler Semantic Errors page 210 Compiler Panics I O Errors page 217 Runtime Errors page 217 Note Appendix B Error Messages lists in numerical order all the error messages generated by Pascal Compiler Syntax Errors Here are some common syntax errors in Pascal programs and the ways that the compiler handles them Illegal Characters Characters such as are not part of Pascal If they are found in the source program and are not part ofa string constant a character constant or a comment they are considered to be illegal characters This error can happen if you leave off a closing string quotation mark 205 206 Most nonprinting characters in your input are also illegal except in character constants and character strings Except for the tab and formfeed characters which are used to format the program nonprinting characters in the input file print as the character in your listing String Errors Encountering an end of line after an opening string quotation mark without first encountering the matching closing quote yields the diagnostic Unmatched for string Also anything enclosed in double quotes for example he1llo is treated as a comment and is therefore ignored Programs containing characters other than in column 1 or in arbitrary based integers can produce this diagnostic because early implementations of Pascal use as a String deli
183. nto a specific set of values for the xarch xchip and xcache options See Table 3 9 for the values For example xtarget sun4 15 is equivalent to xarch v8a xchip micro xcache 2 16 1 Table 3 9 xtarget Expansions xtarget xarch xchip xcache sun4 15 v8a micro 2 16 1 sun4 20 v7 old 64 16 1 sun4 25 v7 old 64 32 1 sun4 30 v8a micro 2 16 1 sun4 40 v7 old 64 16 1 sun4 50 v7 old 64 32 1 sun4 60 v7 old 64 16 1 sun4 65 v7 old 64 16 1 sun4 75 v7 old 64 32 1 sun4 110 v7 old 2 16 1 sun4 150 v7 old 2 16 1 sun4 260 v7 old 128 16 1 sun4 280 v7 old 128 16 1 sun4 330 v7 old 128 16 1 sun4 370 v7 old 128 16 1 sun4 390 v7 old 128 16 1 sun4 470 v7 old 128 32 1 sun4 490 v7 old 128 32 1 sun4 630 v7 old 64 32 1 The Pascal Compiler 63 64 xtarget xarch xchip xcache sun4 670 v7 old 64 32 1 sun4 690 v7 old 64 32 1 sselc v7 old 64 32 1 ssipc v7 old 64 16 1 ssipx v7 old 64 32 1 sslc v8a micro 2 16 1 sslt v7 old 64 32 1 sslx v8a micro 2 16 1 ss1x2 v8a micro2 8 64 1 ssslc v7 old 64 16 1 ssl v7 old 64 16 1 ss1plus v7 old 64 16 1 ss2 v7 old 64 32 1 ss2p v7 powerup 64 31 1 ss4 v8a micro2 8 64 1 ss5 v8a micro2 8 64 1 ssvyger v8a micro2 8 64 1 ss10 v8 super 16 32 4 ss10 hs11 v8 hyper 256 64 1 ss10 hs12 v8 hyper 256 64 1 ss10 hs14 v8 hyper 256 64 1 ss10 20 v8 super 16 32 4 ss10 hs21 v8 hyper 256 64 1 ss10 hs22 v8 hyper 256 64 1 ss10 30 v8 super 16 32 4 ss10
184. o be collected and saved during execution then the data can be used in subsequent runs to improve performance Table 3 6 The xprofile Values Value Meaning collect Collect and save execution frequency for later use by the optimizer The compiler inserts code to measure the execution frequency at a low level During execution the measured frequency data is written into prof files that correspond to each of the source files If you run the program several times the execution frequency data accumulates in the prof files that is output from prior runs is not lost use Use execution frequency data saved by the compiler Optimize by using the execution frequency data previously generated and saved in the prof files by the compiler The source files and the compiler options excepting only this option must be exactly the same as for the compilation used to create the compiled program that was executed to create the prof files tcov Correctly collects data for programs that have source code in header files or make use of C templates See a for information on the old style of profiling the tcov 1 man page and the Profiling Tools manual for more details Code instrumentation is performed similarly to that of a but d files are no longer generated Instead a single file is generated whose name is based off of the final executable For example if the program is run out of foo bar myprog then the data file
185. of Characters The alfa and string types pass simply varying strings are more complicated All pass by reference 118 Pascal 4 0 User s Guide o lll The C function StrVar c include lt string h gt struct TVarLenStr int nbytes char a 26 void StrVar char s10 char s80 struct TVarLenStr vls static char ax 11 abcdefghij static char sx 81 abcdefghijklmnopgrstuvwxyz static char vx 6 varstr strncpy s10 ax 11 strncpy s80 sx 80 strncpy vls gt a vx 6 vls gt nbytes 6 The Pascal main program program StrVarMain output StrVarMain p type TVarStr varying 26 of char var a alfa s string v TVarstr procedure StrVar var a alfa var s string var v TVarStr external c begin StrVar a s v writeln a writeln s writeln v writeln length v length v 2 end StrVarMain The C Pascal Interface 119 lll O The commands to compile and execute StrVar cand StrVarMain p Incorrect use of string in static variable storage Correct solution using the C library routine st rncpy 120 hostname S cc c StrVar c hostnames pe StrVar o StrVarMain p hostname S a out abcdefghij abcdefghijklmnopqrtstuvwxyz varstr length v 6 Avoid constructs that rely on strings being in static variable storage For example you could use mkt emp 3 in Pascal as follows tmp mktemp tmp eph xx
186. of a single procedure or function Uninitialized Variables Pascal does not necessarily set variables to an initial value unless you explicitly request that with the Z option The exception is static variables which are guaranteed to be initialized with zero values Because variable use is not tracked across separate compilation units pc does nothing about uninitialized or unused variables in global scope that is in the main program However pc checks variables with local scope those declared in procedures and functions to make sure they are initialized before being used pc flags uninitialized variables with a warning message Unused Variables Constants Types Labels and Routines 216 If you declare a variable constant type procedure or function in local scope but never use it Pascal gives you a warning message It does not do this for items declared in global scope because you can use the items in a separately compiled unit Pascal 4 0 User s Guide 9 If you declare a label but never use it Pascal gives you a warning This is true even for a label declared in global scope Compiler Panics I O Errors Runtime Errors One class of error that rarely occurs but which causes termination of all processing when it does is a panic A panic indicates a compiler detected internal inconsistency A typical panic message follows pcO internal error line 110 yyline 109 If you receive such a message compilation
187. ommand limit datasize 16M ensures that a single compilation never consumes more than half of the machine s swap space The best setting of data size depends on the degree of optimization requested and the amount of real memory and virtual memory available To find the actual swap space hostname usr sbin swap s To find the actual real memory hostname usr sbin prtconf grep Memory The o option instructs the compiler to name the generated executable filename The default file name for executable files is a out for object files it is the source file name with a o extension For example the following command stores the executable in the file myprog hostname pe o myprog myprog p If you use this option with the c option the name you give is used as the name for the object file The default file name for object files is the source file name witha o extension You cannot give the object file the same name as the source file The P option causes the compiler to use partial evaluation semantics on the boolean operators and and or Left to right evaluation is guaranteed and the second operand is evaluated only if necessary to determine the result Pascal 4 0 User s Guide Oy lll pand pg The p and pg options instruct the compiler to produce code that counts the number of times each routine is called The profiling is based on a periodic sample taken by the system rather than by line counters Using the
188. ompliance as follows e s0 Accept Level 0 compliance with standard Pascal e sor sl Accept Level 1 compliance with standard Pascal This option causes many features of Pascal that are not found in standard Pascal to be diagnosed with warning messages These features include Nonstandard procedures and functions Extensions to the procedure write Padding of constant strings with blanks o o o Preprocessor directives In addition all letters except character strings and constants are mapped to lowercase Thus the case of keywords and identifiers is ignored This option is most useful when a program is to be ported to other machines The sb option produces a database for source browsing The sbfast option performs the same task as sb but does not compile Pascal 4 0 User s Guide Oy lll tC temp dir The tc option instructs the compiler to generate pc3 stab information that allows cross module type checking This option can be used for two purposes e To check for any name conflicts that your program may have with the standard libraries with which it is to be linked such as libc The linker allows name conflicts which may cause erroneous runtime behavior in your program For example the following program has a name conflict with libc program p output var time integer begin writeln wallclock end When the program is compiled with the tc option pc3 issues a warning that
189. only gets through to the C main program when you compile the Pascal routine using the calign option type TDay array 0 8 of char TWeek array 0 6 of TDay TYear array 0 51 of TWeek procedure DaysOfWeek var Yi Tears begin Y 1 1 Sunday end include lt stdio h gt extern C void DaysOfWeek char 52 7 9 int main void char Year 52 7 9 DaysOfWeek Year printf Day Ss An Year 1 1 The C Pascal Interface 145 The commands to compile and execute DaysOfWeek p and DaysOfWeekMain cc without the calign option The commands to compile and execute DaysOfWeek p and DaysOfWeekMain cc withthe calign option The Pascal procedure StruChr p Itis safer for the Pascal procedure to explicitly provide the null byte and include itin the count before the string is passed to C 146 hostname pc c DaysOfWeek p hostname CC DaysOfWeek o DaysOfWeekMain cc lpc hostnames a out Day hostname pe c calign DaysOfWeek p hostname CC DaysOfWeek o DaysOfWeekMain cc lpc hostname a out Day Sunday Records and Structures A Pascal record of an integer and a character string matches a C structure of the same constructs as in this example type TLenStr record NBytes integer ChrStr array 0 24 of char end procedure StruChr var v TLenStr begin v NBytes 14
190. ons for speed and provides close to the maximum performance for most realistic applications A convenience option it chooses the fastest code generation option available on the compile time hardware the optimization level 02 the dalign option and a set of inline expansion templates If you combine fast with other options the last specification applies Solaris 2 x only The fast option includes fns ftrap none that is it turns off all trapping In previous releases the fast macro option included fnonstd now it does not fast includes native in its expansion The code generation option the optimization level and using inline template files can be overridden by subsequent switches For example although the optimization part of fast is 02 the optimization part of fast 03 is 03 Pascal 4 0 User s Guide 3 fnonstd fns Do not use this option for programs that depend on IEFE standard exception handling you can get different numerical results premature program termination or unexpected SIGFPE signals Note The criteria for the fast option vary with the compilers from SunSoft C C FORTRAN 77 Fortran 90 and Pascal See the appropriate documentation for the specifics The fnonstd option causes nonstandard initialization of floating point arithmetic hardware By default IEEE 754 floating point arithmetic is nonstop and underflows are gradual See the Numerical Computation Guide
191. onstants The math_p h file refers to sunmath_p h by an include directive This chapter contains the following sections Contents of the Math Libraries page 234 libm Functions page 235 IEEE Support Functions page 236 SPARC Libraries page 238 Arithmetic Exceptions page 239 Math Library Exception Handling Function matherr page 240 libsunmath Support for IEEE Modes and Exceptions page 242 233 Contents of the Math Libraries Altogether there are three math libraries libm a A set of functions required by the various standards to which the operating system conforms libm so Solaris 2 x only The shared version of libm a libsunmath a A set of functions not required by the standards but are of common use Table 11 1 lists the contents of the math libraries Table 11 1 Contents of Math Libraries Algebraic functions Roots t Euclidean distance Transcendental functions Elementary transcendental functions Trigonometric functions Trigonometric functions of radian arguments Trigonometric functions of degree arguments Trigonometric functions scaled in Pi Trigonometric functions with double precision Pi Hyperbolic functions Exponential logarithm power Financial functions Higher transcendental functions Bessel Gamma Error function Integral rounding functions 234 Pascal 4 0 User s Guide 11 Libm F
192. p s strlen s apointer to procedure argument Call the Pascal routine The C Pascal Interface 131 The Pascal main program ProcParMain p which calls the C procedure proc_c passing it the address of the Pascal procedure proc_pas TheC procedure assigns a value to the string s and calls the procedure whose pointer it just received Then the Pascal procedure proc_pas writes a literal constant and the string it just received The commands to compile and execute ProcPar cand ProcParMain p program ProcParMain type Declare a procedure pointer type proc_ptr procedure var s string i integer Declare an external C procedure which takes a procedure argument procedure proc_c p proc_ptr external c procedure proc_pas var cstr string strlen integer var i integer begin write Hello from PROC_PASCAL for i 1 to strlen do write cstr i writeln proc_pas DO end begin Call the C routine proc_c addr proc_pas end ProcParMain hostname S cc c ProcPar c hostnames pe ProcPar o ProcParMain p hostname S a out Hello from PROC_PASCAL Called from C Procedures and Functions as Parameters 132 It is probably clearer to pass a pointer to a procedure than to pass the procedure name itself See Procedure Calls Pascal C on page 117 A procedure or function passed as an argument is associated with
193. p Option To generate an execution profile using the p option 1 Compile with the p option 2 Run a out which produces a mon out executable file 3 Type prof a out The program prints a profile Using the pg Option To generate an execution profile using the pg option 1 Compile with the pg option 2 Run a out which produces a gmon out executable file a more sophisticated profiling tool than mon out 3 Type gprof a out The program prints a profile pic Kpicand PIC KPIC The pic and PIC options cause the compiler to generate position independent code PIC One of these options should be used for objects which are then put into shared libraries With PIC each reference to a global datum is generated as a dereference of a pointer in the global offset table Each function call is generated in pc relative addressing mode through a procedure linkage table The size of the global offset table is limited to 8Kbytes with pic The PIC option expands the global offset table to handle 32 bit addresses for those rare cases where there are too many data objects for pic For more information on PIC see the section on shared libraries in the Solaris documentation The Pascal Compiler 39 40 Qoption The Qoption passes an option to the program The option value must be appropriate to that program and can begin with a plus or minus sign The program value can be either as 1 Solaris 1 x only fbe 1 Solar
194. parts may not be passed by reference 21360 Cannot pass components of packed structures by reference 21370 Cannot pass components of packed structures by VAR OUT or IN OUT 22010 Ran out of memory gentypind Error Messages 285 286 22020 Ra 22030 Ra 22040 Ra 22050 Ra 22060 Ra 22070 Ra 22080 Ra 22090 out 22100 out 22110 Ra 22120 Ra 22130 Out 22140 out 22150 out 23010 23020 23030 standard 23040 230502 23060 Pascal 4 0 User s Guide ou ou ou ou ou ou ou of of of of of of of me of memory of memory ory ory ory ory ory case hash TRIM defnl buffer_ir_pass ory string ory tralloc Estr out of hash tables out of tree tables of space of tree space put_on_idlist try simplifying of temporary string space lt identifier gt is a non standard function lt identifier gt is a non standard procedure Two argument forms of reset and rewrite are non NIL values in const declaration are non standard Set constants in const declaration are non standard Expressions in const declaration are non standard Ss lll and functions are not standard routine segments are not case statements is non standard Reading scalars from text files is non standard Writing lt ftype gt s with two write widths is non standard 23070
195. passed by Pre defined files input and output redefined Files cannot be members of files Missing closing lt quote or bracket gt for include file name Include filename must end in i or h Error Messages 275 lll Se 15100 Cannot open include file lt filename gt 15110 line lt number gt does not exist in file lt identifier gt 15120 End of fil xpected QUIT 15130 Unexpected end of fil QUIT 16010 lt identifier gt is not a function 16020 Too many levels of function procedure nesting 16030 No assignment to the function variable 16040 Functions should not return lt type gt s 16050 Procedure function nesting too deep 16060 pcc_fvar no result for this function 16070 lt identifier gt is a lt class gt not a function 16080 Illegal function qualification 16090 compiler takes size of function 16100 Can t call lt identifier gt its not a pointer to a procedure or function 16110 Can t qualify a function result value 16120 Cannot assign value to built in function 16130 INTERNAL option illegal for procedure pointer option ignored 16140 Unknown option for procedure pointer ignored lt option gt 16150 Too many levels of function procedure nesting 276 Pascal 4 0 User s Guide Ss lll 16160 Procedure function nesting too deep 16170 Can t call lt identifier gt its not a pointer to a procedure or function 16180 Can t call lt identifier gt
196. procedure Included in each example are the Pascal procedure the C main program and the commands to compile and execute the final program procedure Samp var i integer var r real begin i 7 r 3 14 end Pascal 4 0 User s Guide The C main program SampMain cc The commands to compile and execute Samp p and SampMain ccic include lt stdio h gt extern C void Samp int amp doubles int main void int di double d Samp i d printf Sd 3 2f An i d hostnames pc c Samp p hostname CC Samp o SampMain cc lpc hostnames a out 7 3 14 Arguments Passed by Reference The C Pascal Interface C arguments can be passed by reference This section describes how they work with Pascal 139 lll N Simple Types without the x1 Option Without the x1 option simple types match as in the following example The Pascal procedure procedure SamRef SampRef in the file Samp p var t f boolean var c char var i integer var s integerl6 var r shortreal var d real begin t true f false at i 9 s 9 r 9 9 d 9 9 end 140 Pascal 4 0 User s Guide N lll The C main program SamRefMain cc The commands to compile and execute SamRef p and SamRefMain cc include lt stdio h gt extern C void SamRef char char E char int short
197. program exit_directive p The commands to compile and execute exit_directive p Comments If the compiler encounters an exit directive within an include file it stops processing the include file but continues processing the source file in which it is included In effect sexit is equivalent to an end of file marker When the compiler processes an Sexit directive within an if or ifdef construct it closes all if or ifdefs before it stops processing the current file Example program exit_directive output begin writeln Hello world end exit _directive Sexit Everything after the Sexit is ignored So you can put anything here hostnames pe xl exit_directive p hostname S a out Hello world The i f Directive The if directive is a conditional branching directive Syntax Sif expression then Send if Pascal Preprocessor 257 258 Comments When pc encounters a if directive it evaluates expression If expression is true pc executes the statements in the then part If expression is false pc skips over the then part and executes the else Selseif or Sendi directive If no such directive exists pc proceeds to the next statement The expression consists of a conditional variable and the optional boolean operators and or and not You can set a conditional variable on the command line by using the config option See config on page 27 for information on this optio
198. pubvar_prog p which declares global as public The module unit pubvar_mod p which also declares global as public The commands to compile and execute pubvar_prog pand pubvar_mod p program pubvar_prog public var global integer procedure proc end pubvar_prog external begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global module pubvar_mod public var global integer procedure proc begin writeln From PROC global global global 1 end proc hostname pc xl pubvar_prog p pubvar_mod p pubvar_prog p pubvar_mod p Linking hostname a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 Separate Compilation 81 lll a Using the define Variable Attribute This example makes global public using the define attribute of the variable declaration The program unit program defvar_prog defvar_prog p var global extern integer procedure proc external begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end defvar_prog The module unit defvar_mod p module defvar_mod which makes global public using the define attribute var global define integer procedure proc begin writeln From PROC global global global 1 end proc 82 Pa
199. r used nor set w 18280 field v y is used but never set hostname a out 0 Pascal 4 0 User s Guide 3 m The Pascal main program program p with p with statement type C record re im integer end AC array 1 2 of C RC record Cl C2 C end PRC RC procedure qq var cs Es ac AC res RC pre PRC begin acl ljs ice with ac 1 do begin re 1 writeln im end with prce Cl do begin writeln im end end begin qq end The commands to compile and hostname pe Rw with p execute with p Mon Feb 20 16 28 34 1995 with p In procedure qq w 18280 variable c is used but never set w 18260 variable rc is neither used nor set w 18280 field prc Cl im is used but never set hostname a out 0 a out terminated by signal 11 segmentation violation Traceback being written to a out trace Abort core dumped The Pascal Compiler 45 46 s level sb sbfast The S option compiles the program and outputs the assembly language in the file sourcefile s For example the following command places the assembly language translation of rmc p in the file rmc s No executable file is created hostnames pc S rmc p The s option instructs the compiler to accept standard Pascal only Pascal has two levels of compliance with standard Pascal Level 0 and Level 1 The only difference between the two is that Level 1 also allows conformant arrays Specify the level of c
200. re several incompatibilities between Pascal and FORTRAN variant records enumerated types and set types Variant Records In general Pascal variant records require adjustment of alignment to match with FORTRAN unions and structures Enumerated Types Pascal enumerated types have no comparable type in FORTRAN Pascal 4 0 User s Guide Co lll Pascal Set Types In Pascal a set type is implemented as a bit vector which is similar to a FORTRAN 16 bit word Direct access to individual elements of a set is highly machine dependent and should be avoided Multidimensional Arrays Pascal multidimension arrays are incompatible with FORTRAN multi dimension arrays Since Pascal arrays use row major indexing and FORTRAN arrays use column major indexing an array passed in either direction appears to be transposed General Parameter Passing in FORTRAN and Pascal A few general rules apply to passing parameters By default FORTRAN passes all parameters by reference In FORTRAN if you want to pass anything by value then you must explicitly use the nonstandard function VAL e Pascal passes all parameters by value unless you explicitly state that they are var out or in out parameters in which case they are passed by reference The routine options nonpascal extern fortran and external fortran pass by reference The FORTRAN Pascal Interface 167 8 Procedure Calls FORTRAN Pascal The Pascal procedure
201. rective anywhere in your program Each directive consists of a percent sign followed by the directive name Programs that contain compiler directives must be compiled with the x1 option Table A 1 summarizes the compiler directives Table A 1 cepas Compiler Directives Compiler Directive Description config Sets a special predefined conditional variable with a value of either true or false sdebug Instructs pc to compile this line of code when you use the cond compiler directive selse If expression in Sif expression sthen is false the compiler skips over the Sthen part and executes the else part instead selseif If expression in Sif expression then is false the compiler skips over the then part and executes the elseif part instead Similar to selse elseifdef If expression in ifdef expression then is false the compiler skips over the Sthen part and executes the telseifdef part instead Senable Sets a conditional variable to true sendif Indicates the end of an if or ifdef directive error Prints a string on the standard output and treats it as an error Pascal 4 0 User s Guide Table A 1 cppas Compiler Directives Continued Compiler Directive Description Sexit Stops processing the current Pascal source file Sif When the compiler encounters a if expression then directive it evaluates expression If expression is true pc executes the statem
202. res 105 124 sharing declarations 88 strings by value 114 value parameters 129 to 130 297 var parameters 94 117 C programming language 137 to 162 arguments passing of by reference 139 155 by value 150 157 arrays fixed 144 C calls Pascal 138 to 155 character strings 142 compatible types 138 compiler options 137 function return values 152 159 functions 155 global variables in C and Pascal 161 lpc and 1c options 137 name encoding 138 parameter passing 152 Pascal calls C 155 to 160 file pointers to C 162 interface 137 records and structures 146 value parameters 158 calign option to pc command 26 cg the code generator 18 cg89 option to pc command 26 cg92 option to pc command 26 character data type 33 46 characters illegal 205 compatible types Pascal and C 90 Pascal and C 138 Pascal and FORTRAN 165 compiler 8 11 17 to 66 driver 18 panics 217 compiler directives 246 to 263 include 67 config 247 debug 27 249 else 250 elseif 251 selseifdef 252 Senable 246 254 Pascal 4 0 User s Guide Sendif 255 Serror 255 Sexit 256 Sif 247 257 Sifdef 255 257 258 Sinclude 259 263 Slist 260 Snolist 262 Sslibrary 263 Svar 247 258 263 warning 263 compiler semantic errors 210 to 217 can t read and write scalars 212 expression diagnostics 212 function and procedure type errors 211 goto statement 216 incompatible types 210 procedu
203. res and functions as parameters 211 scalar 211 type equivalence 214 uninitialized variables 216 unreachable statements 215 unused item errors 216 compiler syntax errors 205 to 209 digits in real numbers 206 expected symbols malformed constructs 208 expected unexpected end of file QUIT 209 illegal characters 205 replacements insertions deletions 207 string errors 206 undefined or improper identifiers 208 compiling a Pascal program 8 13 units 69 with libraries XView 224 cond option to pc command 27 249 conditional compilation 27 variables 246 config option 245 252 256 defined 246 undefined 245 Sconfig directive 247 config option to pc command 27 246 252 conformant arrays parameters between Pascal and C 101 114 123 parameters between Pascal and C 152 158 159 parameters between Pascal and FORTRAN 182 193 conventions xxi cpp include directive 67 the C preprocessor 18 27 40 49 245 cppas 245 to 263 compiler directives 246 to 263 conditional variables 245 preprocessor 27 40 the x1 preprocessor 18 19 D D option to pc command 27 dalign option to pc command 28 data type character 33 46 data types XView 226 dbx 3 31 61 debug compiler directive 27 249 debugger 3 debugging disable Auto Read for dbx 61 fix and continue feature 3 with dbx 3 with g option to pc command 31 declarations define 83 sharing between multiple units of
204. ring not lt type gt Argument to card must be a set not lt type gt flush takes at most one argument flush s argument must be a file not lt type gt Not enough arguments to lt function gt 265 266 10120 Too many arguments to lt function gt 10130 Actual argument cannot be conformant array 10140 Actual argument is incompatible with formal var parameter lt identifier gt of lt function gt 10150 Actual argument is incompatible with formal lt paramtype gt parameter lt identifier gt of lt function gt 10160 Actual argument to NONPASCAL procedure cannot be conformant array 10170 Extra arguments to ADDR ignored lt type gt not lt type gt not lt type gt not lt type gt lt identifier gt 10250 Argument 10260 Argument to 10210 Illegal argument to IN_RANG 10220 Type clash in argument to IN_RANGI 10180 Argument to lt function gt must be of type lt type gt not 10190 Second argument to lt function gt must be of type lt type gt 10200 First argument to lt function gt must be of type lt type gt q GJ 10230 Illegal argument to ADDR 10240 Third argument to lt function gt must be of type lt type gt to ADDR is a dynamically allocated variable ADDR is an internal variable lt identifier gt 10280 10270 Argument to Argument to ADDR is an internal p Pascal 4 0 User s Guide ADDR is a nested function lt
205. rmant arrays are not permitted Pascal 4 0 User s Guide B 11170 For statement variable lt identifier gt cannot be an element of a record 1190 1200 1210 1220 1230 11240 lt gt 11250 1260 11270 1280 1290 1300 12010 12020 12030 12040 12050 1180 allowed only on records not on lt type gt s lt identifier gt is not a field in this record Record required when specifying variant tags Missing case constants in variant record lt identifier gt is a duplicate field name in this record Duplicate variant case label in record lt operation gt not allowed on records only allow and Variable in with statement refers to lt identifier gt not to a record Too many tag fields No variant case label value equals specified constant value Tag fields cannot be lt type gt s Bad variant constant variant required after cas Assert expression must be Boolean not lt type gt s illegal transfer function with lt identifier gt Illegal transfer function Transfer functions on bit fields not implemented Oct hex allowed only on writeln write calls Error Messages 271 272 12060 calls 12070 12080 12090 12100 12110 121203 12130 12140 12150 12160 12170 12180 12190 130103 13020 13030 13040 13050 13060 Width expressions allowed only in writeln write
206. ry makes no attempt to determine which identifier or what number should be inserted Thus these are considered fatal syntax errors program synerr_example output var i j are integer begin for j 1 to 20 begin write j 2 Ji writeln i end end synerr_example hostname pe synerr p Mon Feb 13 10 56 19 1995 synerr p 3 var i j are integer 18460 s Replaced identifier with a 6 for j 1 to 20 begin E 18490 5 Expected keyword null E 18460 S Replaced with a identifier e 18480 de Inserted keyword do 8 1 2 3 18480 a Inserted keyword if E 18480 i Inserted identifier 18480 A Inserted keyword then 9 writeln i 18450 Deleted Error Diagnostics 207 lll Ko Undefined or Improper Identifiers If an identifier is encountered in the input but is undeclared the error recovery mechanism replaces it with an identifier of the appropriate class Further references to this identifier are summarized at the end of the containing procedure function or at the end of the program This is the case if the reference occurs in the main program Similarly if you use an identifier in an inappropriate way for example if a type identifier is used in an assignment statement pc produces a diagnostic and inserts an identifier of the appropriate class Further incorrect references to this identifier are flagged only if they involve incorrect use
207. s e 1d the linker which generates the executable files using any libraries necessary to resolve undefined symbols The above is the default action of pc some compiler options change what pc calls Pascal 4 0 User s Guide Oy lll Figure 3 1 shows the sequence of events when you invoke pc Compiler pc Symbol con m flict checking pc3 Compiler Compiler Code Link a T preprocessor frontend generator editor del ON cpp Or cppas pco cg ld Optimize with Optimizer O level option iropt Libraries Figure 3 1 Organization of Pascal Compilation Language Preprocessor The cpp 1 program is the C language preprocessor The compiler driver pc normally calls cpp 1 during the first pass of a Pascal compilation If you use the x1 switch pc calls the alternate preprocessor cppas Then cpp 1 and cppas operate on files that contain the extension p or pas You can give directives to cpp 1 or cppas to define constants conditionally compile parts of your program include external files and take other actions For example the following program shows the use of an include directive which asks cpp 1 to copy the named file into the program before compilation The Pascal Compiler 19 program showinclude include file i begin end See the man page for cpp 1 for information on its directives and other
208. s 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 Preface xxi Shell Prompts in Command Examples Related Documentation xxii Manual Page 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 This manual is designed to accompany the following documents e The Pascal 4 0 Reference Manual which describes extensions to standard Pascal e 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 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 com
209. s integer OOO O x se oO oO procedure SimVal t boolean ch Char si integerl6 i integer sr shortreal r double var Reply integer external c begin SimVal t f c si i sr Y args writeln args args 6 oct end SimVal hostname cc c SimVal c hostnames pe SimVal o SimValMain p hostname S a out args 111111 Function Return Values 130 Function return values match types in the same manner as with parameters and they pass in much the same way See Variable Parameters on page 94 The following example shows how to pass simple types Pascal 4 0 User s Guide o lll The C function RetReal c double RetReal double x return x 1 0 The Pascal main program RetRealMain p program RetRealMain var r s real function RetReal var x real real begin 2 0 sS RetReal r writeln r 4 1 s 4 1 E xternal c end RetRealMain The commands to compile and hostname cc c RetReal c execute RetReal c and hostname pc RetReal o RetRealMain p RetRealMain p hostname a out 2 0 3 0 Parameters That Are Pointers to Procedures Pascal has a special type that is a pointer to a procedure A variable of this type can be used as a parameter as follows The C function ProcPar c include lt string h gt void proc_c void p char s s Called from C
210. s implemented as a bit vector which is similar to a C short word array where each short word contains two bytes Thus sets are bit vectors and they are allocated in multiples of 16 bits To find out the size of a set enter the following code ceiling ord highest_element 16 Direct access to individual elements of a set is highly machine dependent and should be avoided General Parameter Passing in C and Pascal A few general rules apply to parameter passing C passes all arrays by reference since C strings are arrays C passes all structures by value In C if you want to pass anything else by reference then you must explicitly prepend the reference ampersand 8 or pass an explicit pointer Pascal passes all parameters by value unless you explicitly state that they are var in out or out parameters in which case they are passed by reference Procedure Calls C Pascal The Pascal procedure Samp in the file Samp p Note the procedure definition Here are examples of how a C main program calls a Pascal procedure procedure Samp var i integer var r real begin i 9 r 9 9 end Samp The C Pascal Interface 93 lll O The C main program SampMain c Note the procedure definition and call The commands to compile and execute Samp p and SampMain c include lt stdio h gt extern void Samp int int main void int Tei double d
211. s of the MicroSPARC II chip hyper Use timing properties of the HyperSPARC chip hyper2 Use timing properties of the HyperSPARC II chip powerup Use timing properties of the Weitek PowerUp chip ultra Use timing properties of the UltraSPARC chip Same as cg89 Same as cg92 Solaris 2 x only The xF option enables performance analysis of the executable file using the SPARCworks Performance Analyzer and Debugger This option also causes the assembler to generate some debugging information in the object file necessary for data collection The compiler generates code that can be reordered at the function level It takes each function in the file and places it into a separate section For example functions cn1 and fcn2 are placed in the sections text fcnl and text fcn2 You can control the order of functions in the final executable by using the xF and the loader Mmapfile options In the map file if you include the flag O in the string of segment flags then the static linker 1d attempts to place sections in the order they appear in the map file See the Solaris documentation for details about this option the segment flags and the map file The Pascal Compiler 55 56 xildoff xildon x1 Solaris 2 x only Turns off the incremental linker and forces the use of 1d This option is the default if you do not use the g option or you do not use the G option or any source files are present on the command
212. scal 4 0 User s Guide nN lll The commands to compile and execute defvar_prog pand defvar_mod p The program unit defvar_prog p hostname S pc xl defvar_prog p defvar_mod p defvar_prog p defvar_mod p Linking hostname S a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 Using the define Declaration This example defines global in the module defvar_mod2 using the define declaration The advantage of using the define declaration over the define variable attribute is that the define declaration can be easily converted to use include files program defvar_prog var global extern integer procedure proc external begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end defvar_prog Separate Compilation 83 III a The module unit module defvar_mod2 defvar_mod2 p which defines global ina define declaration Dar global extern integer define global procedure proc begin writeln From PROC global global global 1 end proc The commands to compile and hostname pe xl defvar_prog p defvar_mod2 p execute defvar_prog pand defvar_prog p defvar_mod2 p defvar_mod2 p Linking hostname S a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 Using include Files In the following example the extern declaration for the v
213. scal Programs 11 12 Using the same program but with the lt operator to redirect input you can print the file on the terminal hostname copy lt data hello are you listening goodbye I must go now Using a File Name as a File Variable You can also redirect the output by listing the file as a file variable in the program statement The Pascal library associates the file variable with a file of the same name For example copy2 p lists data as the input file variable program copy2 data output This program redirects input var ey chars data text begin reset data while not eof data do begin while not eoln data do begin read data C write c end readin data writeln end end copy2 Pascal 4 0 User s Guide 2 Assuming that the file data is still in the current directory you can compile and run the program as follows hostname pc o copy2 copy2 p hostname S copy2 hello are you listening goodbye I must go now Where Did My Program Fail SPARCompiler Pascal can trace why a program failed its traceback utility finds the routine that triggers the error Using Pascal Traceback Pascal traceback installs signal handlers on selected signals and dumps a backtrace when those signals are caught The backtrace shows the chain of calls leading from the routine in which the error occurred all the way back to the main program Pascal ca
214. scal alfa and string types are arrays C passes all arrays by reference The C counterpart to the Pascal varying is a structure C passes structures by value Before you call Pascal with a null varying string set the byte count to zero because that is what Pascal assumes about such strings C can pass a structure consisting of a four byte integer and an array of characters to a Pascal procedure expecting a var parameter that is a variable length string See the following example type TVarStr varying 25 of char procedure StrVar var a alfa var s string var v TVarStr begin a abcdefghi chr 0 s abcdefghijklmnopgrstuvwxyz chr 0 y varstr chr 0 end StrVar Pascal 4 0 User s Guide The C main program StrVarMain c The commands to compile and execute StrVar pand StrVarMain c include lt stdio h gt include lt string h gt struct TVarLenStr int nbytes char a 25 y extern void StrVar char char struct TVarLenStr int main void struct TVarLenStr vls char s10 10 s80 80 s25 25 vls nbytes 0 StrVar s10 s80 amp vls strncpy s25 vls a vls nbytes printf s10 s An s80 S s s10 s80 s25 printf strlen s25 d In n s25 s strlen s25 hostname pe c StrVar p hostname ca StrVar o StrVarMain c lpc hostname a out s10 abcdefghi s80 abcdefghijklmnopqrtstuvwxyz s25 varstr strlen
215. ses a header file program program_unit2 output include header h begin say_hello end In this case the content of header h is very simple procedure say_hello extern Pascal 4 0 User s Guide In a real program header h would probably contain many declarations and would be included in several modules Aside from routine declarations header files often contain constant type and variable declarations Sharing Variables Between Units Variables that are global across a unit that is not declared locally in a routine can be public or private A public variable can be shared by any unit that is linked to the unit that declares the variable A private variable cannot be shared You can use the public and private reserved words to declare that a var section declares public or private variables For example program program_unit3 output public var x integer private var y integer When you do not use public or private variables are public by default However when you compile with the x1 option variables are private by default To share a public variable simply declare it in each unit where you want to share it As long as the variable is public each reference to that variable accesses the same data Program Construction and Management 71 72 Here is a program unit that declares a variable program program_unit3 output var x integ
216. sion type clashed with type of value parameter lt identifier gt of lt identifier gt 21030 Expression given variable required for var parameter lt identifier gt of lt identifier gt 21040 Parenthesis not allowed for var parameter lt identifier gt of lt identifier gt 21050 Parameter type not identical to type of var parameter lt identifier gt of lt identifier gt 21060 Packed unpacked type conflict between formal and actual parameters Error Messages 283 284 21070 Conformant array parameters in the same specification must be the same typ 21080 actual parameter is not an array 21090 array index type is incompatible with conformant array parameter lt identifier gt 21100 array index type is not within of index type of conformant array parameter lt identifier gt 21110 array index type is not within range lt number gt lt number gt of index type of conformant array parameter lt identifier gt 21130 lt class gt lt identifier gt given for formal lt class gt parameter lt identifier gt 21140 does not match type of formal lt class gt parameter lt identifier gt line lt number gt 21150 lt class gt parameter lt identifier gt of lt identifier gt line lt number gt 21160 does not match lt class gt parameter lt identifier gt of lt identifier gt line lt number gt 21170 Type of lt class gt parameter lt identifier gt of lt identifier gt
217. sors menus scrollbars and frames A frame contains non overlapping subwindows within its borders You manipulate an object by passing a unique identifier or handle for that object to procedures associated with that object Object Oriented Programming Traditional programs are made up of procedures When you need to operate on some data you pass the data to a procedure This style of programming can be referred to as procedure oriented programming In object oriented programming the data are organized into objects which are similar to records in that an object can contain data fields of different types In addition to data though objects also have associated procedures called methods The methods of an object generally perform all operations that can be performed on the data of the object When you need to operate on the data in an object you direct the object to do the operation This is referred to as sending a message to the object and is similar to calling a procedure Each object is an instance of a given class A class is much like a type in that it defines a kind of object Creating an instance of a given class is much like declaring a variable of a given type since creating an instance of a class creates an object that has the properties and characteristics defined for its class Classes are different from types in that a class can inherit data fields and methods from another class In fact you always define a new class by decl
218. tches the following set of signals SIGQUIT SIGIOT SIGFPE SIGSYS SIGTERM SIGILL SIGABRT SIGBUS SIGPIPE SIGLOST SIGTRAP SIGEMT SIGSEGV See the signal 3 man page for further information on these signals After the system produces the traceback it continues with whatever action it would have taken if the interposer had not been in place including calling a user signal handler that was previously set The traceback facility uses the debugger dbx To obtain a traceback SPARCworks must be installed on your system and the directory containing dbx must be in your PATH environment variable If the traceback routine cannot find dbx it does not produce the traceback Use the not race command line option to disable traceback Pascal Programs 13 Using a Sample Program with Segmentation Violation A segmentation violation occurs when your program tries to reference memory outside your address space The operating system detects this action and generates an error message Following is an example program SegViol p which contains a segmentation violation program SegmentationViolation type Pinteger integer procedure ErrorlnHere var IntVar integer NullPtr Pinteger begin NullPtr nil Next statement causes a SEGV IntVar NullPtr end procedure Calll procedure Call2 begin ErrorlinHere end begin Call2 end begin Calll end Compiling and Runnin
219. te Types Aggregate types include arrays varying arrays sets strings alphas records and variant records Pascal aggregate types may require alignment and layout adjustment to match C unions structures and arrays Pascal aggregate types can be any of the following arrays varying arrays sets strings alphas records or variant records However you can use the calign option to eliminate some of these differences With calign the following assumptions are made e Pascal records have the same data layout as C structures e Arrays have the same data layout in both languages However if you use the x1 option in addition to calign boolean arrays with an odd number of elements are different e Pascal variants are the same as C unions Incompatibilities This section describes the incompatibilities between C and Pascal types Enumerated Types C enumerated types are incompatible with Pascal enumerated types Pascal enumerated types are represented internally by sequences of integral values starting with 0 Storage is allocated for a variable of an enumerated type as if the type was a subrange of integer For example an enumerated type of fewer than 128 elements is treated as 0 127 which according to the rules above is equivalent to a char in C C enumerated types are allocated a full word and can take on arbitrary integer values Pascal 4 0 User s Guide O lll Pascal Set Types In Pascal a set type i
220. ten to files are often difficult to interpret In fact if you define type color red green blue standard Pascal does not associate these constants with the strings red green and blue in any way Pascal adds an extension so that enumerated types can be read and written however if the program is to be portable you must write your own routines to perform these functions Standard Pascal only allows the reading of characters integers and real numbers from text files including input not strings or booleans You can make the following declaration file of color However the representation is binary rather than as strings and it is impossible to define input as other than a text file Expression Diagnostics The diagnostics for semantically ill formed expressions are explicit as the following program shows This program expr p is admittedly far fetched but illustrates that the error messages are clear enough so you can easily determine the problem in the expressions Pascal 4 0 User s Guide O lll program expr_example output var a set of char b Boolean c red green blue p integer A alfa B packed array 1 5 of char begin b true c red new p a 1 A Hello yellow b a and b a a 3 if input lt 2 then writeln boo if p lt 2 then writeln sure nuff if A B then writeln same if c true then writeln hue s and color s nd
221. ter was eetee wes 200 Function Return Vales espada Etre 201 Routines as Par meter criados ri es 202 9 Error Diagnostics 1 ri RANA 205 Compiler Syntax BUTLER 205 Mesh veneer aleeeedeees te ee ee ees ers 205 SINE BMGs cdv casa seen eee ee AAA ARA 206 Digits in Real Numbers sis4 24 anecesies ne ee a ed 206 Replacements Insertions and Deletions 207 Undefined or Improper Identifiers 2 00 ccc cee eens 208 Expected Symbols and Malformed Constructs 208 Expected and Unexpected End of file 209 Compiler Semantic Errors ox eseews iia 210 Format of the Error DiagnosticS ooooooocoooom o 210 Incompatible VY PGs ds as o cd AAA AAA 210 Contents Xi 10 The scalar Class 2 0 0 0 cece eek ee eee eee AREER E 211 Procedure and Function Type Errors 211 Scalar Error Messages uso pa dec s 212 Expression Diagnostico 212 Type Equivalente cipisppiria tr drena 214 Unreachable Statements src 215 The goto Statement anans eed dipun a eee heinei 216 Uninitialized Variables nunnana 216 Unused Variables Constants Types Labels and Routines 216 Compiler Panics I O Errors mec 217 Runtime Errors o 24 sence bebe eee ra 217 Whe X View Toolkit ici AE RARAS 221 OVEIVIEWococoos ae e A 221 A ee el ey eed eee eee ee oes 222 O one e eee See Pee eee ee ees 222 Object Oriented Programming ovis decay Ve yusenne eum 222 Pascal Interface ccornsorin ERRATA 223
222. the FORTRAN source there is no explicit analogue in Pascal So if you try to simply pass an actual string and specify the FORTRAN routine as extern fortran the program fails because implementation of this type of arguments implies that the actual length of the string is implicitly passed as an extra value argument after the string pointer To specify this routine in Pascal declare it as having two arguments a VAR argument of string type for the string pointer and an extra value argument of integer32 type for the string length It is incorrect to specify the routine as extern fortran because Pascal passes all arguments to FORTRAN routines by reference Consequently to pass this type of argument you must Declare two arguments as described above specifying the routine as simply external without the fortran directive Add a trailing underscore to the routine name in a Pascal program The FORTRAN Pascal Interface 189 111 Co The Pascal program sun pas The FORTRAN subroutine mygrout f The commands to compile and run this program 190 The following example illustrates this method program Test input output var s string procedure mygrout_ var prompt string length begin writeln Starting s Trio Jeepy mygrout_ s 8 writeln Ending lend integer32 external subroutine MyGrout N character N write 6 N return end hostname pe g c su
223. the command line Pascal 4 0 User s Guide Oy lll When the compiler encounters an option followed by This is what happens The current value is pushed onto the stack and the current value becomes ON The current value is pushed onto the stack and the current value becomes OFF The last value is popped off the stack and becomes the current value If no values have been pushed onto the stack the effect of is undefined Figure 3 2 illustrates how options are passed in program text Program Output program options output hostname pe options p begin end 1 Turns on listing 4 writeln After 1 writeln After 1 5 l Turns off listing 1 Turns off listing 6 Notice that this line prints Notice that this line prints 10 writeln After 1 writeln After 1 11 end 1 Turns listing on again Notice that this line does not print writeln After 1 Fri Mar 1 17 33 18 1995 options p Options Figure 3 2 Options in Program Text This section describes all the pc command options in alphabetical order Unless otherwise stated at the beginning of the description for the option all of these options work for both the Solaris 1 x and Solaris 2 x environments In general processing of the compiler options is from left to right so selective overriding of macros can be done This rule does not apply to linker options T
224. the name time is already defined as a libc routine Running a out causes a core dump To avoid this problem change the name of the variable that has the conflict in this case time e To check for possible name conflicts in the various modules of your program These conflicts arise if you define a routine with the same name in several modules or refer to an external but undefined variable The linker detects these error situations and does not create the executable file The temp option instructs pc to locate the temporary files that it creates during compilation in the directory named dir For example the following command puts the temporary files in the current directory hostname pe temp hello p If you do not specify a temporary directory pc places the temporary files in the tmp directory The Pascal Compiler 47 lll Oy time The time option instructs the compiler to report execution performance statistics for the various compilation passes Here is some sample output some spaces have been removed so the output would fit on the page hostname pc cpp time U 0 pcO time U 0 cg time U 0 as time U 0 pc3 time U 0 time hello p Ost S Ost S Ost S Ost S 1s S oooo0o 1s 0 2s 3s 0 4s 15s 0 2s 28 0 3s 15s 0 3s ld time U 0 8s S 0 9s 1 8sSR REAL 1 6s 11 core T 0k D 0k io IN 4b OUT 3b pf IN 25p OUt 184p REAL 3 2s 13 core T 0k D
225. ties capital_letters digits red yellow set of boolean VAY ae ae blue Pascal Preprocessor 261 A The listing includes the time each unit was compiled and the name of each unit compiled 262 hostname pe x1 list p Tue Feb 28 15 48 1995 list p 6 list Tue Feb 28 15 50 1995 types h 1 type 2 lowints 0 100 3 primary_colors set of red yellow blue 4 possibilities set of boolean 5 capital_letters set of A Z 6 digits set of lowints 8 var 9 pri primary_colors 10 pos possibilities 11 cap Capital_letters 12 dig digits Tue Feb 28 15 52 1995 list p 7 Sinclude types h hostname S a out There are 3 primary colors There are 2 possibilities There are 26 Capital letters There are 101 digits The no1ist Directive The nolist directive disables the program listing Syntax Snolist Comments S nolist is the default Example See the example under The list Directive Pascal 4 0 User s Guide A The Sslibrary Directive cppas treats Sslibrary in the same manner as the include directive See The include Directive on page 259 The Svar Directive The Svar directive defines conditional variables for the preprocessor Syntax Svar varl varN Comments A conditional variable is defined when it appears in a bvar directive otherwise it is undefined Example See the example under The conf
226. to compile r p and the Rw warnings that are issued The Pascal main program rr p two records Examples program p procedure qq type compl record re im integer end arc array 1 2 of compl var z compl a arc begin writeln z im writeln a 1 re end begin end hostnames pc Rw r p Fri Jan 27 17 35 50 1995 Ep In procedure qq w 18280 field z im is used but never set w 18280 field a re is used but never set program p type r record a b integer end procedure qq var irl 62310 var i integer begin i rl a i r2 a i r1 b i r2 b end begin qq end The Pascal Compiler 43 lll Oy The commands to compile rr p andthe Rw warnings that are issued The Pascal main program recvar p variant record The commands to compile recvar p 44 hostnames pc Rw rr p Mon Feb 20 14 59 04 1995 pas rr p In procedure qq w 18280 field rl w 18280 field rl w 18280 field r2 w 18280 field r2 b is used but never set a is used but never set b is used but never set a is used but never set program p procedure qq type r record x y integer case integer of O a integer l bt char end var v T begin vo x Ls writeln v y end begin qq end hostname pe Rw recvar p Mon Feb 20 15 55 18 1995 recvar p In procedure qq w 18260 field v a is neither used nor set w 18260 field v b is neithe
227. uch more slowly on earlier architectures to the left in the above list Table 3 3 The xarch Values Value Meaning generic Get good performance on most SPARCs and major degradation on none This is the default This option uses the best instruction set for good performance on most SPARC processors without major performance degradation on any of them With each new release this best instruction set will be adjusted if appropriate v7 Limit the instruction set to V7 architecture This option uses the best instruction set for good performance on the V7 architecture but without the quad precision floating point instructions This is equivalent to using the best instruction set for good performance on the V8 architecture but without the following instructions The quad precision floating point instructions The integer mul and div instructions The fsmuld instruction Examples SPARCstation 1 SPARCstation 2 v8a Limit the instruction set to the V8a version of the V8 architecture This option uses the best instruction set for good performance on the V8 architecture but without The quad precision floating point instructions The fsmuld instruction Example Any machine based on MicroSPARC I chip architecture The Pascal Compiler 51 52 Table 3 3 The xarch Values Continued Value Meaning v8 v8plus Limit the instruction set to V8 architecture This option uses the best instruction set for
228. ui en restreignent l utilisation la copie et la d compliation Aucune partie de ce produit ou de sa documentation associ e ne peuvent Etre reproduits sous aucune forme par quelque moyen que ce soit sans l autorisation pr alable et crite de Sun et de ses bailleurs de licence s il ena Des parties de ce produit pourront etre derivees du syst me UNIX licenci par UNIX System Laboratories Inc filiale entierement detenue par Novell Inc ainsi que par le syst me 4 3 de Berkeley licenci par Universit de Californie Le logiciel d tenu par des tiers et qui comprend la technologie relative aux polices de caract res est prot g par un copyright et licenci par des fourmisseurs de Sun LEGENDE RELATIVE AUX DROITS RESTREINTS l utilisation la duplication ou la divulgation par l administration americaine sont soumises aux restrictions vis es a l alin a c 1 ii de la clause relative aux droits des donn es techniques et aux logiciels informatiques du DFARS 252 227 7013 et FAR 52 227 19 Le produit d crit dans ce manuel peut Etre protege par un ou plusieurs brevet s americain s etranger s ou par des demandes en cours d enregistrement MARQUES Sun Sun Microsystems le logo Sun Sun Microsystems Computer Corporation Solaris le Sun Microsystems Computer Corporation logo SunSoft le SunSoft logo ProWorks ProWorks TeamWare ProCompiler Sun 4 SunOS ONC ONC NFS OpenWindows DeskSet ToolTalk SunView XView X11 Ne
229. unctions Table 11 1 Contents of Math Libraries Continued Random number generators Additive pseudo random generators Linear pseudo random generators Random number shufflers IEEE support functions IEEE functions t IEEE test IEEE values IEEE sun Control flags Floating point trap handling IEEE handling Handling for specific SIGFPE codes in libc Error handling function Data conversion BSD miscellaneous Base conversion routines in 1ibc FORTRAN intrinsic functions Legend m Functions available in bundled libm m Functions available in bundled 1ibm and as single precision version only in libsunmath Functions available in unbundled 1ibm libsunmath Most numerical functions are available in double and single precision version In general the names of the single precision version are formed by adding f to the names of the double precision version Math Libraries 235 11 The following Pascal program is an example of how to use math functions program TestLibm output include lt math_p h gt var d0 d1 d2 double f0 f1 f2 single begin d0 0 0 dl 1 0 d2 2 0 0 lt 0 07 1 1 0 2 2 0 writeln Trigonometric functions writeln sin d0 writeln sinf f0 sincos M_PI_2 dl d2 writeln dl d2 sincosf M_PI_2 fl 2 writeln f1 f2 writeln Exponential logarithm power writeln exp d1 writeln log d1
230. 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 Pascal 4 0 User s Guide lll Licensing Locale 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 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
231. vy Chrstr St Petersburg chr 0 end Pascal 4 0 User s Guide The C main program StruChrMain cc The commands to compile and execute StruChr p and StruChr cc include lt stdio h gt include lt string h gt struct TVarLenStr int NBytes char a 25 extern C void StruChr TVarLenStr amp int main void struct TVarLenStr vls char 25 25 vls NBytes 0 StruChr vls strncpy s25 vls a vls NBytes printf s25 Ss An 825 printf strlen s25 d n strlen s25 hostnames pe c StruChr p hostname CC StruChr o StruChrMain cc lpc hostname a out s25 St Petersburg strlen s25 13 The C Pascal Interface 147 lll N The Pascal procedure DayWeather p 148 Consider this example type TDayWeather record TDay array 0 8 Weather array 0 20 end TDayWeatherArray array procedure DayWeather var W TDayWeatherArray var WeatherSiz integer i begin W 1 TDay Sunday W 1 TWeather Sunny WeatherSize 5 end of char of char 0 1 of TDayWeather Pascal 4 0 User s Guide The C main program DayWeatherMain cc include lt stdio h gt include lt string h gt struct TDayRec char TDay 9 char TWeather 21 extern C void DayWeather TDayRec 2 int amp int main void printf weather s
232. ween UnitS o oo o o 71 IORAMIES oo IAE Es 74 5 Separate CompilatiO osiorivins 0s rra da Es 75 Working with Unils cad bite ai 75 Using Program nds 595999690040 76 Using Module Units escisiones 76 Sharing Variables and Routines Across Multiple Units 76 Compiling without the x1 Option 77 Using the 8 DP suei pai AN 80 Sharing Declarations in Multiple Units 87 6 The C Pascal Interface socmorirrrrsr rana 89 Compilation of Mixed Language Programs 89 Compatibility of Types for C and Pascal 90 Precautions with Compatible Types 91 Incomipatibintes i410 lt cleverereecedeeee ts ee ee eee ers 92 General Parameter Passing in C and Pascal 93 Procedure Calls C Pascal ocioteca AREA 93 Variable Parameters coria ab 94 Value Parameters aa io E 112 Function Return Values prpsisoneeie its 115 Input and Output cri 116 Procedure Calls Pascal or eee tea A e 117 Variable Parameters csr soswe ted iy eed AOS 117 Value Parameters pri ANNA 129 Contents ix Function Return Values 0 0 cece ee ee eee 130 Parameters That Are Pointers to Procedures 131 Procedures and Functions as Parameters 132 Global Variables in C and Pascal coooomeommm rcconns 133 File Passing Between Pascal and C ooooccoocooccooo mo 134 7 The C Pascal Interface ooooooocoocmo
233. werBook 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 1 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 1SO7185 at both level 0 and level 1 lll Pascal Compiler Features Compatibility 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 l
234. which it is used 24060 For statement variable lt identifier gt cannot be lt type gt s 24070 Can t modify the for statement variable lt identifier gt in the range of the loop 24080 Incorrect control variable 24090 Type of initial expression clashed with index type in for statement 24100 Type of limit expression clashed with index type in for statement 24110 Can t modify the for variable lt identifier gt in the range of the loop Pascal 4 0 User s Guide Ss lll 24120 Case selectors cannot be lt type gt s 24130 Duplicate otherwise clause in case statement 24140 Case label type clashed with case selector expression type 24150 Multiply defined label in case lines lt number gt and lt number gt 24160 No case list elements 24170 Bad case constant 24180 Range in case label must be in ascending order 24190 Maximum number of case selectors exceeded 24200 Cannot next not within a loop 24210 Goto lt label gt is into a structured statement 24220 Goto lt label gt from line lt number gt is into a structured statement 24230 Variable in with statement refers to lt type gt not to a record 24240 Maximum WITH nesting depth exceeded ignoring WITH variables 24250 Variable in with statement not correct 24260 cannot assign to lhs 24270 Variable required 24280 lt class gt lt identifier gt found where variable required 24290 univ_ptr variable
235. writeln Fahrenheit Celsius writeln rog for fahren MIN to MAX do begin celsius CONVERT fahren 32 writeln fahren 5 celsius 18 2 end end Compiling the Program Now compile the program with pc the Pascal compiler by typing at the system prompt hostname pe temp p Pascal names the compiled version of the program a out by default Pascal 4 0 User s Guide No lll Running the Program To run the program enter a out at the prompt The output of temp p is then displayed hostnames a out Fahrenheit Celsius 32 0 00 33 0 56 34 1 11 35 1 67 36 2 22 37 2 78 38 3 33 39 3 89 40 4 44 41 5 00 42 5 56 43 6 11 44 6 67 45 7 22 46 7 78 47 8 33 48 8 89 49 9 44 50 10 00 Renaming the Executable File It is inconvenient to have the result of every compilation in a file called a out If such a file already exists it is overwritten You can avoid this in either of the two following ways Change the name of a out after each compilation with the mv command hostnames mv a out temp e Use the compiler o option to name the output executable file This example places the executable code in the file temp hostnames pc o temp temp p Pascal Programs 9 Now run the program by typing the name of the executable file The output follows hostnames temp Fahrenheit Celsius 32 0 00 33 0 56 34 1 11 An Interactive Pascal Program 10 In Pascal the pre
236. writeln pow d1 dl writeln expf f1 writeln logf f1 writeln powf fl f1 end IEEE Support Functions 236 This section describes the IEEE support functions including ieee_functions ieee _values and i _retrospective Pascal 4 0 User s Guide 11 ieee functions The functions described in ieee_functions 3M provide capabilities either required by the IEEE standard or recommended in its appendix Example program TestIE EEFunctions output include math_p h var dl double 1 0 d2 double 2 0 il integer 1 begin writeln IEEE functions writeln ilogb d1 writeln isnan dl writeln copysign d1 d2 writeln fabs d1 writeln fmod dl dl writeln nextafter dl dl writeln remainder d1 dl writeln scalbn d1 11 end leee values IEEE values such as infinity NaN minimum and maximum positive floating point numbers are provided by special functions described in the ieee_values 3M man page Another example follows Math Libraries 237 11 program TestlEE EValues output include math_p h var 10 integer32 0 begin writeln IEEE values writeln infinity writeln signaling_nan 10 writeln quiet_nan 10 writeln max_normal writeln max_subnormal writeln min_normal writeln min_subnormal end leee
237. xxxx This use is incorrect since mkt emp modifies its argument Instead use the C library routine strncpy see string 3 to copy the string constant to a declared char array variable as in program Use_mktemp procedure strncpy var dest univ string var srce univ string length integer external c procedure mktemp var dest univ string external c var path string begin strncpy path tmp eph xxxxxx sizeof path mktemp path end Pascal 4 0 User s Guide The C function FixVec c The Pascal main program FixVecMain p The commands to compile and execute FixVec c and FixVecMain p Fixed Arrays For a fixed array parameter pass the same type and size as in this example void FixVec int V 9 int Sum int i Sum 0 for i 0 i lt 8 i Sum Sum V i program FixVecMain output type TVec array 0 8 of integer var V TVec Os ly 27 Sy Es Sy Oe Y Sum integer procedure FixVec var XV TVec var XSum begin FixVec V Sum writeln Sum 3 end FixVecMain 81 integer external c hostname cc c FixVec c hostname hostname pe calign FixVec o FixVecMain p 36 a out the array parameter is an array of aggregates The calign option is not needed for this example but may be necessary if The C Pascal Interface 121 lll O The C function
238. y 262144 end The C Pascal Interface 151 lll N The C main program include lt stdio h gt SimValMain cc extern C void SimVal char char char short int float double int amp int main void char t 1 f 0 c z short si 9 int i 9 float sr 9 9 double r 9 9 int args SimVal t f c si i sr Y args printf args 5070 An args return 0 The commands to compile and hostname pe c SimVal p execute SimVal p and hostname CC SimVal o SimValMain cc lpc SimVal cc hostnameS a out args 111111 Function Return Values Function return values match types in the same manner as with parameters They pass in much the same way 152 Pascal 4 0 User s Guide Sz Simple Types Simple types pass in a straightforward way as in the following example The Pascal function function RetReal r real real RetReal p begin RetReal r 1 end The C main program include lt stdio h gt RetRealMain cc extern C double RetReal double int main void double E Si r 2 0 s RetReal r printf Sf An s The commands to compile and hostname pe c RetReal p execute RetReal p and hostname CC RetReal o RetRealMain cc lpc RetRealMain cc hostnames a out 3 000000 The C Pascal Interface 153 lll N The Pascal function RetShortReal p The C main pro
239. ype clash string and unpacked array 25210 Type clash string and packed array with lower bound lt gt 1 25220 Type clash Non identical string types must be packed 25230 Type clash packed array with lower bound lt gt 1 25240 Set default type intset is not a set 25250 Upper bound of element type clashed with set type in constant set 25260 Lower bound of element type clashed with set type in constant set 25270 Element type clashed with set type in constant set 25280 Set elements must be scalars not lt type gt s 25290 Set of real is not allowed 25300 Procedures cannot have types 25310 Function type Can be specified only by using a type identifier Error Messages 291 lll Se 25320 Function type should be given only in forward declaration 25330 Different type declared previously for function return lt name gt 25340 Function type must be specified 25350 Type of expression in while statement must be Boolean not lt type gt 25360 Until expression type must be Boolean not lt type gt in repeat statement 25370 Array index type incompatible with declared index type 25380 Too many subscripts 25390 Bad type of variable used for call 25400 Transfer functions only work on types of the same size 25410 Only type char allowed in varying array 25420 Type mismatch in read from non text file 25430 Type mismatch in write to non text file 25440 Specified tag consta
Download Pdf Manuals
Related Search
Related Contents
User`s Manual 大使フラッシュバルブ Manual de Instalação e Manutenção Série ITV20*0-X156 CASHFLOW® 126 and CASHFLOW® 129 USER GUIDE Fiche explicative Holtzwihr Jeu du portrait et Degas Bedienungsanleitung Lustiges Pilotenbrillen-Gestell für User Manual D4139 User interface Comfort™ Series User Manual Copyright © All rights reserved.
Failed to retrieve file