background image

The C++–Pascal Interface

151

7

Simple Types without the

-xl

 Option

Without the

-xl

 option, simple types match, as in the following example:

The Pascal procedure,

SimVal.p

procedure SimVal(

  t, f: boolean;

  c: char;

  si:integer16;

  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;

Summary of Contents for SunSoft Pascal 4.0

Page 1: ...Pascal4 0User sGuide Part No 802 2943 10 Revision A November 1995 A Sun Microsystems Inc Business 2550 Garcia Avenue Mountain View CA 94043 U S A ...

Page 2: ...pt 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 Sta...

Page 3: ...ntroduction 1 Standards 1 Pascal Compiler 2 Features 2 Compatibility 2 Text Editors 3 Debuggers 3 XView Toolkit 3 Native Language Support 3 Internationalization 4 Locale 5 Licensing 5 2 Pascal Programs 7 A Simple Pascal Program 7 ...

Page 4: ...g a File Name as a File Variable 12 Where Did My Program Fail 13 Using Pascal Traceback 13 Using a Sample Program with Segmentation Violation 14 3 The Pascal Compiler 17 pc Version Number 17 Compile and Link Sequence 18 Language Preprocessor 19 File Name Extensions Accepted By pc 20 Option Passing on the Command Line 21 Option Passing in the Program Text 21 Options 23 a 24 Bbinding 24 b 24 bsdmall...

Page 5: ...26 calign 26 cg89 26 cg92 26 cond 26 config 27 Dname def 27 dalign 28 dn 28 dryrun 28 dy 28 fast 28 fnonstd 29 fns 29 fround r 29 ftrap t 30 G 30 g 31 H 31 hname 31 help or flags 32 Ipathname 32 i name 32 keeptmp 32 ...

Page 6: ...directory 33 libmieee 34 libmil 34 llib 34 misalign 34 mt 34 native 35 nocx 35 nolib 35 nolibmil 35 noqueue 35 notrace 36 O level 36 o filename 38 P 38 p and pg 39 pic Kpic and PIC KPIC 39 Qoption 40 Qpath pathname 40 Qproduce 40 qp 40 R 41 ...

Page 7: ...vii R path dir 41 Rw 41 S 46 s level 46 sb 46 sbfast 46 tc 47 temp dir 47 time 48 U name 49 V 49 V0 and V1 49 v 49 w 49 xa 49 xarch a 49 xcache c 53 xchip c 54 xcg89 55 xcg92 55 xF 55 xildoff 56 xildon 56 xl 56 ...

Page 8: ...57 xnolib 57 xnolibmopt 57 x05 57 xpg 58 xprofile p 58 xregs r 60 xs 61 xsafe mem 61 xsb 61 xsbfast 61 xspace 62 xtarget t 62 Z 66 ztext 66 4 Program Construction and Management 67 Units 67 Using Program Units and Module Units 68 Compiling with Units 69 Using Units and Header Files 70 ...

Page 9: ...ption 80 Sharing Declarations in Multiple Units 87 6 The C Pascal Interface 89 Compilation of Mixed Language Programs 89 Compatibility of Types for C and Pascal 90 Precautions with Compatible Types 91 Incompatibilities 92 General Parameter Passing in C and Pascal 93 Procedure Calls C Pascal 93 Variable Parameters 94 Value Parameters 112 Function Return Values 115 Input and Output 116 Procedure Cal...

Page 10: ...38 C Name Encoding 138 Procedure Calls C Pascal 138 Arguments Passed by Reference 139 Arguments Passed by Value 150 Function Return Values 152 Procedure Calls Pascal C 155 Arguments Passed by Reference 155 Arguments Passed by Value 157 Function Return Values 159 Global Variables in C and Pascal 161 Pascal File Pointers to C 162 8 The FORTRAN Pascal Interface 163 Compiler Mixed Language Programs 16...

Page 11: ...rameters 197 Pointers 200 Function Return Values 201 Routines as Parameters 202 9 Error Diagnostics 205 Compiler Syntax Errors 205 Illegal Characters 205 String Errors 206 Digits in Real Numbers 206 Replacements Insertions and Deletions 207 Undefined or Improper Identifiers 208 Expected Symbols and Malformed Constructs 208 Expected and Unexpected End of file 209 Compiler Semantic Errors 210 Format...

Page 12: ...atement 216 Uninitialized Variables 216 Unused Variables Constants Types Labels and Routines 216 Compiler Panics I O Errors 217 Runtime Errors 217 10 The XView Toolkit 221 Overview 221 Tools 222 Objects 222 Object Oriented Programming 222 Pascal Interface 223 Compiling with Libraries 224 Header Files 224 Attribute Lists 225 Handles 226 Data Types 226 Coding Fragment 227 Conversion of C to Pascal 2...

Page 13: ...am 231 11 Math Libraries 233 Contents of the Math Libraries 234 libm Functions 235 IEEE Support Functions 236 ieee_functions 237 ieee_values 237 ieee_retrospective 238 SPARC Libraries 238 Arithmetic Exceptions 239 Math Library Exception Handling Function matherr 240 libsunmath Support for IEEE Modes and Exceptions 242 ...

Page 14: ...xiv Pascal 4 0 User s Guide ...

Page 15: ...xv Figures Figure 3 1 Organization of Pascal Compilation 19 Figure 3 2 Options in Program Text 23 Figure 10 1 A Sample Class Hierarchy 223 ...

Page 16: ...xvi Pascal 4 0 User s Guide ...

Page 17: ...Values 54 Table 3 6 The xprofile Values 59 Table 3 7 The xregs Values 60 Table 3 8 The xtarget Values 62 Table 3 9 xtarget Expansions 63 Table 6 1 C and Pascal Size and Alignment of Compatible Types 90 Table 6 2 C and Pascal Size and Alignment of Compatible Types with xl 91 Table 6 3 Set Implementation 110 Table 8 1 Default Sizes and Alignments of Compatible Types Pascal and FORTRAN 165 xl with xl...

Page 18: ...xviii Pascal 4 0 User s Guide Table 10 1 C Declarations to Pascal Declarations 228 Table 11 1 Contents of Math Libraries 234 ...

Page 19: ...emain in the documentation as being for Solaris 1 x only The README file that accompanies the product contains other release specific information Note All references to Pascal in this manual refer to the Pascal 4 0 compiler unless otherwise indicated Operating Environment For information on the operating environment see the README file Installation For instructions on how to install Pascal refer t...

Page 20: ... 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 progra...

Page 21: ... a b Either a or b a Zero or one instance of a a Zero or more instances of a abc The characters abc Table P 2 Typographic Conventions Typeface or Symbol Meaning Example AaBbCc123 The names of commands files and directories on screen computer output Edit your login file Use ls a to list all files hostname You have mail AaBbCc123 What you type contrasted with on screen computer output hostname su Pa...

Page 22: ...n viewing tool that takes advantage of dynamically linked headings and cross references The Installing SunSoft Developer Products SPARC Solaris manual shows you how to install AnswerBook Manual Page Pascal 4 0 provides an on line manual page also known as man page on pc 1 that describes the Pascal compiler This document is included in the Pascal package and must be installed with the rest of the s...

Page 23: ...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 Docu...

Page 24: ...Numerical Computation Guide X AnswerBook README X CD ROM What Every Scientist Should Know About Floating Point Arithmetic X AnswerBook and CD ROM Table P 4 Documents in Hard Copy and in AnswerBook Continued Title Hard Copy On Line ...

Page 25: ...dards Pascal is a derivative of the Berkeley Pascal system distributed with UNIX 4 2 BSD It complies with FIPS PUB 109 ANSI IEEE 770 X3 97 1983 and BS6192 ISO7185 at both level 0 and level 1 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 ...

Page 26: ...time initializations static and extern declarations Different sizes of integer and real data types Integer constants in any base from 2 to 16 Extended input output facilities Extended library of built in functions and procedures Universal and function and procedure pointer types Direction of parameter passing into a routine out of a routine or both Functions that return structured type results Not...

Page 27: ...tools are available dbx A symbolic debugger debugger A window and mouse based version of the symbolic debugger You can use Pascal with fix and continue a debugger functionality See the debugger documentation for details of this feature XView Toolkit The XView application programmer s interface API is an object oriented and server based user interface toolkit for the X Window System Version 11 X11 ...

Page 28: ... support for localized messages and text presentation Level 4 Contains Asian language support Pascal supports all four levels See the Pascal 4 0 Reference Manual for a description of the date and time functions in internationalized formats Pascal does not allow input and output in the various international formats If it does it does not comply with the Pascal language standard ANSI IEEE 770 X3 97 ...

Page 29: ...loper Products SPARC Solaris When you invoke the compiler if a license is available the compiler starts If no license is available your request for a license is put on a queue and your compile job continues when a license becomes available A single license can be used for any number of simultaneous compiles by a single user on a single machine There are two licensing related options noqueue Does n...

Page 30: ...6 Pascal 4 0 User s Guide 1 ...

Page 31: ...ing 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 ...

Page 32: ... Pascal names the compiled version of the program a out by default 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 writeln Fahrenheit Celsius writeln for fahren MIN to MAX do begin celsius CONVERT fahren 32 writeln fahren 5 celsius 18 2 end end ...

Page 33: ...ten You can avoid this in either of the two following ways Change the name of a out after each compilation with the mv command hostname mv a out temp Use the compiler o option to name the output executable file This example places the executable code in the file temp hostname pc o temp temp p hostname 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 ...

Page 34: ...milarly 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 hostname temp Fahrenheit Celsius 32 0 00 33 0 56 34 1 11 program copy input output This program copies input to output var c char begin while not eof do begin while not eoln do ...

Page 35: ...ine you type The program terminates when you type the end of file Control d character at the beginning of a line Try it Redirecting I O To write the output to a file instead of to the terminal use the redirection operator followed by a file name For instance to write to a file called data enter the following hostname copy hello are you listening hello are you listening goodbye I must go now goodby...

Page 36: ...able 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 hostname copy data hello are you listening goodbye I must go now program copy2 data output This program redirects input var c char data text begin reset data while not eof data do begin while not eoln data do begin read data c write c ...

Page 37: ...ignals 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...

Page 38: ...ontains a segmentation violation Compiling and Running 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 program SegmentationViolation type Pinteger integer procedure ErrorInHere var IntVar integer NullPtr Pinteger begin NullPtr nil Next statement causes a SEGV...

Page 39: ... name of each routine hostname pc SegViol p hostname a out a out terminated by signal 11 segmentation violation Traceback being written to a out trace Abort core dumped hostname more a out trace Stacktrace of a out Program terminated due to segmentation violation 3 __PC0__sigdie 0xb 0xefffedf0 0xefffec30 0x0 0x1 0x0 at 0x12128 called from signal handler with signal 11 SIGSEGV 4 ErrorInHere at 0x11...

Page 40: ...a out terminated by signal 11 segmentation violation Traceback being written to a out trace Abort core dumped hostname more a out trace Stacktrace of a out Program terminated due to segmentation violation 3 __PC0__sigdie 0xb 0xefffedf0 0xefffec30 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 Call1 line 21 ...

Page 41: ...pc Version Number 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 pc Version Number page 17 Compile and Link Sequence page 18 Language Preprocessor page 19 File Name Extensions...

Page 42: ...l 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 xl option pc0 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...

Page 43: ...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 Compiler pc Optimizer iropt Compiler frontend p...

Page 44: ...ishes the compilation linking and loading program showinclude include file i begin end 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 suffi...

Page 45: ...ions 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 P H I l 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 bufferin...

Page 46: ... 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 the command line 1 The options p and t are different when they are used within program text and when they are used on the command line because they are received directly ...

Page 47: ...os can be done This rule does not apply to linker options 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 program options output begin l Turns on listing ...

Page 48: ...k 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 Bbinding 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 objec...

Page 49: ... a This option also causes the flags u _malloc lib libbsdmalloc a to be passed to the linker C The C option enables runtime 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 ...

Page 50: ... 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 variables of that type cg89 Solaris 1 x only The cg89 option generates code to run on generic SPARC architecture Solaris 2 x only This option is a ma...

Page 51: ...e xl 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 variable the value of the predefined conditional variable config is set to true xl runs your program through the preprocessor cppas which handles the Apoll...

Page 52: ...ast Solaris 1 x only The fast option selects optimum compilation options 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 s...

Page 53: ...rdware 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 lm to the linker Solaris 2 x only This option is a synonym for fns ftrap common fns Solaris 2 x only T...

Page 54: ...E 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 none the default turns off all trapping modes A no prefix...

Page 55: ... g turns off inlining that you usually get with 04 H 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 hname 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 ld In general the name ...

Page 56: ...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 file 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 i name The i option produces a listing for the specified procedure function i...

Page 57: ... option produces a listing of the program For example 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 ld library search path for ld hostname pc l random p Pascal PC Version SC4 0 09 Jan 1995 Pascal 4 0 Mon...

Page 58: ...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 mt The mt option uses multithread safe libraries eliminates conflicts between threads so that Pascal library routines...

Page 59: ...not to link any libraries by default that is no l options are passed to ld Normally the pc driver passes lc to ld When you use nolib pass all l options yourself For example the following command links libm statically and the other libraries dynamically hostname pc nolib Bstatic lm Bdynamic lc test p nolibmil The nolibmil option instructs the compiler to reset fast so that it does not include inlin...

Page 60: ...erpreted as follows O This is the most likely level of optimization to give fastest performance for most reasonable applications The default is O2 O1 xO1 This is the minimum amount of optimization peephole and is postpass assembly level Do not use O1 unless O2 and O3 result in excessive compilation time or shortage of swap space O2 xO2 This is the basic local and global optimization induction vari...

Page 61: ... and O4 may result in an increase in the size of the executables When optimizing for size use level O2 For most programs O4 is faster than O3 which is faster than O2 which is faster than O1 However in a few cases O2 may be faster than the others and O3 may be faster than O4 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...

Page 62: ...ame usr sbin swap s To find the actual real memory hostname usr sbin prtconf grep Memory o filename 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 pc o myprog myprog p If...

Page 63: ...more sophisticated profiling tool than mon out 3 Type gprof a out The program prints a profile pic Kpic and 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 tab...

Page 64: ...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 pc Qpath home pascal sparc testp p Qproduce The Qproduce option instructs pc to...

Page 65: ...enerates 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 th...

Page 66: ...ized If such a field is used but not set it is denoted as V F in the warning message 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 f and its componen...

Page 67: ... writeln a 1 re end begin end The commands to compile r p and the Rw warnings that are issued hostname pc Rw r p Fri Jan 27 17 35 50 1995 r p In procedure qq w 18280 field z im is used but never set w 18280 field a re is used but never set The Pascal main program rr p two records program p type r record a b integer end procedure qq var r1 r2 r var i integer begin i r1 a i r2 a i r1 b i r2 b end be...

Page 68: ...er set w 18280 field r2 a is used but never set The Pascal main program recvar p variant record program p procedure qq type r record x y integer case integer of 0 a integer 1 b char end var v r begin v x 1 writeln v y end begin qq end The commands to compile recvar p hostname pc 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 ...

Page 69: ... writeln im end with prc C1 do begin writeln im end end begin qq end The commands to compile and execute with p hostname pc Rw 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 C1 im is used but never set hostname a out 0 a out terminated by signal 11 segmentation violation Traceback being w...

Page 70: ...e as follows s0 Accept Level 0 compliance with standard Pascal s or s1 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 Preprocessor directives In ad...

Page 71: ...out causes a core dump To avoid this problem change the name of the variable that has the conflict in this case time 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...

Page 72: ...ly 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 hostname pc time hello p cpp time U 0 0s S 0 1s 0 2s REAL 1 6s 11 core T 0k D 0k io IN 4b...

Page 73: ...that insert checks into the object file as follows v The v verbose option prints the command line used to call each compilation pass w 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...

Page 74: ...on 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 ...

Page 75: ... 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 inst...

Page 76: ... addressing mode but the upper 32 bits of the i and l 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 on a v7 or v8 machine v8plusa Limit the instruction set to the V8plusa version of the V9 architecture By defintion V8plusa means the V8plus...

Page 77: ...r cache property is used 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 Table 3 4 The xcache Values Value Meaning generic 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 m...

Page 78: ...way the compiler uses branches The instructions to use in cases where semantically equivalent alternatives are available Level 1 cache has 16K bytes 32 bytes line size 4 way associativity Level 2 cache has 1024K bytes 32 bytes line size Direct mapping associativity Table 3 5 The xchip Values Value Meaning generic Use timing properties for good performance on most SPARCs This is the default value t...

Page 79: ...he sections text fcn1 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 ld 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 ...

Page 80: ...re no source files present on the command line Override this default by using the xildoff option xl The xl option implements a set of features that provide broad compatibility with Apollo Pascal We recommend using xl 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 xl When you use xl the c...

Page 81: ... option the compiler 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 opt...

Page 82: ...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 xpg Same as p and pg xprofile p Solaris 2 x only The xprofile p option collects data for a profile or use a profi...

Page 83: ...ce 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 fo...

Page 84: ...he 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 no appl Do not use the appl registers float Allow using the floating point registers as specified in the SPARC ABI You can use these registers eve...

Page 85: ... must move the source files but you need not move the object o files Auto Read This is the newer and default way of loading symbol tables The compiler distributes this information in the o files so that dbx loads the symbol table information only if and when it is needed The linker links faster and dbx initializes faster If you move the executables to another directory then to use dbx you must mov...

Page 86: ...description of the target computer hardware When program performance is critical the proper specification of the target hardware could be 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 c...

Page 87: ...ple 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 ol...

Page 88: ...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 40 v8 super 16 32 4 ss10 41 v8 super 16 32...

Page 89: ...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 ss...

Page 90: ...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 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 ultra1 140 v8 ultra 16 32 1 512 64 1 ultra1 170 v8 ultra 16 32 1 512 64 1 ultra1 ...

Page 91: ...m 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 the line include includefile is a compiler directive to cpp 1 the Pascal compiler s preprocessor The directive instructs cpp 1 to find the file inclu...

Page 92: ...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 com...

Page 93: ...y 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 th...

Page 94: ...alling pc when you call ld 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 cre...

Page 95: ...y 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 When you do not use public or private variables are public by default However when you compile with the xl option variables are private by default To share a public varia...

Page 96: ...le Here is a module unit that declares a variable with the same name program program_unit3 output var x integer procedure say_hello external begin for x 1 to 5 do say_hello end module module_unit3 var x integer procedure say_hello begin writeln Hello world for the x time end ...

Page 97: ...s it is often a good idea to declare 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 hostname pc program_unit3 p module_unit3 p program_unit p module_unit p Linking hostname a out Hello world for the 1 time Hello world for...

Page 98: ...th 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 descri...

Page 99: ...oss the different units and then invokes ld 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 ld directly so there is no consistency checking Independent compilation is ...

Page 100: ...x module unit module heading declaration list The module heading contains the reserved word module followed by an identifier module heading module identifier For example This is a legal module heading The module heading is optional Sharing Variables and Routines Across Multiple Units Pascal supports three methods of sharing variables and routines between units include files Multiple variable decla...

Page 101: ... 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 The program unit shrvar_prog p 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 Themoduleunit shrvar_mod p The assign...

Page 102: ...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 and or double quotation marks The different enclosures and affect the search order for files The syntax for the include directi...

Page 103: ...prog The module unit inc_mod p which also includes the file include h module inc_mod include include h procedure proc begin writeln From PROC global global global 1 end proc The include file include h var global integer procedure proc extern The commands to compile and execute inc_prog p and inc_mod p hostname pc inc_prog p inc_mod p inc_prog p inc_mod p Linking hostname a out From MAIN before PRO...

Page 104: ...signment 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 xl 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 x...

Page 105: ...N after PROC global end pubvar_prog The module unit pubvar_mod p which also declares global as public module pubvar_mod public var global integer procedure proc begin writeln From PROC global global global 1 end proc The commands to compile and execute pubvar_prog p and pubvar_mod p hostname pc xl pubvar_prog p pubvar_mod p pubvar_prog p pubvar_mod p Linking hostname a out From MAIN before PROC 1 ...

Page 106: ...og p 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 The module unit defvar_mod p which makes global public using the define attribute module defvar_mod var global define integer procedure proc begin writeln From PROC global global global 1 end proc ...

Page 107: ...ily converted to use include files The commands to compile and execute defvar_prog p and defvar_mod p hostname pc xl defvar_prog p defvar_mod p defvar_prog p defvar_mod p Linking hostname a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 The program unit defvar_prog p program defvar_prog var global extern integer procedure proc external begin global 1 writeln From MAIN before PROC g...

Page 108: ...the extern definition The module unit defvar_mod2 p which defines global in a define declaration module defvar_mod2 var global extern integer define global procedure proc begin writeln From PROC global global global 1 end proc The commands to compile and execute defvar_prog p and defvar_mod2 p hostname pc xl defvar_prog p defvar_mod2 p defvar_prog p defvar_mod2 p Linking hostname a out From MAIN b...

Page 109: ...extern begin global 1 writeln From MAIN before PROC global proc writeln From MAIN after PROC global end proc The module unit inc_mod2 p module inc_mod2 define global include include2 h procedure proc begin writeln From PROC global global global 1 end proc The include file include2 h var global extern integer ...

Page 110: ...n the module that defines the procedure This declaration nullifies the effect of the extern declaration The commands to compile and execute inc_prog2 p and inc_mod2 p hostname pc xl inc_prog2 p inc_mod2 p inc_prog2 p inc_mod2 p Linking hostname a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 The program unit ext_prog p program ext_prog include extern h begin global 1 writeln From ...

Page 111: ...ompiler from SunSoft Then external c directs the compiler to generate calling sequences compatible with SunSoft C compiler The module unit ext_mod p module ext_mod define global proc include 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 execute ext_prog p and ext_...

Page 112: ...ernal procedure to conform to a naming convention of the f77 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 g...

Page 113: ...grams You must use the compiler option lpc when you compile a C main routine that calls Pascal lpc includes the Pascal object library libpc For example hostname pc c calign my_pascal p hostname cc my_pascal o my_c c lpc 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 Pr...

Page 114: ...hostname pc calign my_c o my_pascal p Compatibility of Types for C and Pascal Table 6 1 and Table 6 2 list the default sizes and alignments of compatible types for C and Pascal Table 6 1 C and 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 integer16 short int 2 2 ...

Page 115: ... static variable storage You can satisfy these assumptions as follows 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 array array Same as element type variant record struct union fields in pac...

Page 116: ...yout as C structures Arrays have the same data layout in both languages However if you use the xl option in addition to calign boolean arrays with an odd number of elements are different 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 ...

Page 117: ...ply 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 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 ref...

Page 118: ...an do too The C main program SampMain c Note the procedure definition and call include stdio h extern void Samp int double int main void int i double d Samp i d printf d 3 1f n i d The commands to compile and execute Samp p and SampMain c hostname pc c Samp p hostname cc Samp o SampMain c hostname a out 9 9 9 ...

Page 119: ...olean var c char var si integer16 var i integer var sr shortreal var r real begin t true f false c z si 9 i 9 sr 9 9 r 9 9 end SimVar The C main program SimVarMain c include stdio h extern void SimVar char char char short int float double int main void char t f c short si int i float sr double r SimVar t f c si i sr r printf 08o 08o c d d 3 1f 3 1f n t f c si i sr r ...

Page 120: ...e 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 The commands to compile and execute SimVar p and SimVarMain c hostname pc c SimVar p hostname cc SimVar o SimVarMain c hostname a out...

Page 121: ...tern 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 vls strncpy s25 vls a vls nbytes printf s10 s n s80 s n s25 s n s10 s80 s25 printf strlen s25 d n strlen s25 The commands to compile and execute StrVar p and StrVarMain c hostname pc c StrVar p hostname cc StrVar o StrVarMain c lpc hostname a out s10 abcdefghi s80 ...

Page 122: ...o the C main program when you compile the Pascal routine using calign The Pascal procedure FixVec p 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 The C main program FixVecMain c include stdio h extern void FixVec int int int main void int Sum static int a 0 1 2 3 4 5 6 7 8 FixVec a Sum printf d n Sum Th...

Page 123: ...d DaysOfWeek char 7 9 int main void char Year 52 7 9 DaysOfWeek Year printf Day s n Year 1 1 The commands to compile and execute DaysOfWeek p and DaysOfWeekMain c without calign hostname pc c DaysOfWeek p hostname cc DaysOfWeek o DaysOfWeekMain c lpc hostname a out Day The commands to compile and execute DaysOfWeek p and DaysOfWeekMain c with calign hostname pc c calign DaysOfWeek p hostname cc Da...

Page 124: ...iv arrays that are in out in out or var parameters pass by reference The Pascal procedure UniVec p which defines a 10 element array 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 The C main program UniVecMain c which passes a 3 element array to the Pascal procedure written to do a 1...

Page 125: ...are declared in the same parameter group With multidimensional arrays for all dimensions but the last one pass the low bound high bound and element width The commands to compile and execute UniVec p and UniVecMain c with calign hostname pc c calign UniVec p hostname cc UniVec o UniVecMain c lpc hostname a out 24 function ip var x array lb ub integer of real real extern double ip double int int dou...

Page 126: ... 1 Single Dimension Array The Pascal procedure IntCA p Pascal passes the bounds pair procedure IntCA var a array lb ub integer of integer begin a 1 1 a 2 2 end IntCA The C main program IntCAMain c include stdio h extern void IntCA int int int int main void int k static int s 0 0 0 IntCA s 0 sizeof s 1 for k 0 k 3 k printf d n s k The commands to compile and execute IntCA p and IntCAMain c with cal...

Page 127: ...c Array M has 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 wr is the width of a row element next largest and is equal to c2 c1 1 wc include stdio h define NC 3 define NR 2 extern void RealCA double NC int int int int int int main void double M NR NC int col c1 c2 row...

Page 128: ...efinition is recursive Example 3 Array of Characters The commands to compile and execute RealCA p and RealCAMain c with calign hostname pc c calign RealCA p hostname cc RealCA o RealCAMain c lpc hostname a out 1 0 0 0 0 0 0 0 1 0 0 0 The Pascal procedure ChrCAVar p procedure ChrCAVar var a array lb ub integer of char begin a 0 T a 13 o end ChrCAVar The C main program ChrCAVarMain c For C the lower...

Page 129: ...u 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 The commands to compile and execute ChrCAVar p and ChrCAVarMain c hostname pc c calign ChrCAVar p hostname cc ChrCAVar o ChrCAVarMain c lpc host...

Page 130: ... c include stdio h include string h struct TVarLenStr int NBytes char a 25 extern void StruChr struct TVarLenStr int main void struct TVarLenStr vls char s25 25 vls NBytes 0 StruChr vls strncpy s25 vls a vls NBytes printf s25 s n s25 printf strlen s25 d n strlen s25 The commands to compile and execute StruChr p and StruChrMain c hostname pc c StruChr p hostname cc StruChr o StruChrMain c lpc hostn...

Page 131: ... var WeatherSize integer begin W 1 TDay Sunday chr 0 W 1 TWeather Sunny chr 0 WeatherSize 5 end StruChr The C main program DayWeatherMain c include stdio h include string h struct TDayRec char TDay 9 char TWeather 21 extern void DayWeather struct TDayRec int int main void char s25 25 char t25 25 struct TDayRec dr 2 int nbytes 0 DayWeather dr nbytes strncpy s25 dr 1 TDay 6 printf day s n s25 strncp...

Page 132: ...on The commands to compile and execute DayWeather p and DayWeatherMain c without calign hostname pc c DayWeather p hostname cc DayWeather o DayWeatherMain c lpc hostname a out day weather sun The commands to compile and execute DayWeather p and DayWeatherMain c with calign hostname pc calign c DayWeather p hostname cc DayWeather o DayWeatherMain c lpc hostname a out day Sunday weather sunny The Pa...

Page 133: ...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 tag a x var_part a_var ch1 a x var_part a_var ch2 b VarRec x printf c n x var_part a_var ch2 The commands to compile and execute VarRec p and VarRecMain c hostname pc c calign VarRec p hostname cc VarRec o VarRecMain c lpc hostname a out Z ...

Page 134: ...s With the current set representation it does not matter what the lower bound value is The nth element in a set lower upper can be tested as follows 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 define LG2BITSLONG 5 log2 bits in long word define LG2BITSWORD 4 log2 bits in short word defin...

Page 135: ...rn 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 4 w p printf 012o 3d n p w printf 110 001 010 binary word 4 n printf 876 543 210 bits word 4 n The commands to compile and execute IntSetVar p and IntSetVarMain c The output of this example depends on the architecture of your machine hostname pc c IntSetVar p hostname cc IntSetVar...

Page 136: ...l procedure SimVal p t f c i r and s are value parameters procedure SimVal t f boolean c char si integer16 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 ...

Page 137: ...ith xl With xl the Pascal real must be paired with a C float and the Pascal integer must be paired with a C short int The C main program SimValMain c include stdio h 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 r 9 9 int args SimVal t f c si i sr r args printf args 06o n args The commands to compile and exec...

Page 138: ...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 The Pascal procedure ChrCAVal p procedure ChrCAVal a array lb ub integer of char begin a 0 T a 13 o end ChrCAVal The C main program ChrCAValMain c includ...

Page 139: ...ollows The commands to compile and execute ChrCAVal p and ChrCAValMain c with calign hostname pc c calign ChrCAVal p hostname cc ChrCAVal o ChrCAValMain c lpc hostname a out This is a string The Pascal function RetReal p function RetReal x real real begin RetReal x 1 0 end RetReal The C main program RetRealMain c include stdio h extern double RetReal double int main void double r s r 2 0 s RetReal...

Page 140: ...rogram just before exit add the following line See this example The commands to compile and execute RetReal p and RetRealMain c hostname pc c RetReal p hostname cc RetReal o RetRealMain c hostname a out 3 000000 __PC0__PCSTART __PC0__PCEXIT The Pascal procedure IO p procedure IO begin writeln Hello Pascal and St Petersburg end The C main program IOMain c include stdio h extern void IO int main voi...

Page 141: ...s all variable parameters by reference which C can do too Simple Types Simple types pass in a straightforward manner as follows The commands to compile and execute IO p and IOMain c hostname pc c IO p hostname cc IO o IOMain c lpc hostname a out Hello Pascal and St Petersburg Hello C The C function SimRef c void SimRef char t char f char c short si int i float sr double r t 1 f 0 c z si 9 i 9 sr 9...

Page 142: ...t f boolean c char si integer16 i integer sr shortreal r real procedure SimRef var t f boolean var c char var si integer16 var i integer var sr shortreal var r real external c begin SimRef t f c si i sr r writeln t f 6 c 2 si 2 i 2 sr 4 1 r 4 1 end SimRefMain The commands to compile and execute SimRef c and SimRefMain p hostname cc c SimRef c hostname pc SimRef o SimRefMain p hostname a out true f...

Page 143: ... 81 abcdefghijklmnopqrstuvwxyz static char vx 6 varstr strncpy s10 ax 11 strncpy s80 sx 80 strncpy vls a vx 6 vls nbytes 6 The Pascal main program StrVarMain p program StrVarMain output 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 StrVa...

Page 144: ...mands to compile and execute StrVar c and StrVarMain p hostname cc c StrVar c hostname pc StrVar o StrVarMain p hostname a out abcdefghij abcdefghijklmnopqrtstuvwxyz varstr length v 6 Incorrect use of string in static variable storage tmp mktemp tmp eph xxxxxx Correct solution using the C library routine strncpy program Use_mktemp procedure strncpy var dest univ string var srce univ string length ...

Page 145: ...Vec c void FixVec int V 9 int Sum int i Sum 0 for i 0 i 8 i Sum Sum V i The Pascal main program FixVecMain p program FixVecMain output type TVec array 0 8 of integer var V TVec 0 1 2 3 4 5 6 7 8 Sum integer procedure FixVec var XV TVec var XSum integer external c begin FixVec V Sum writeln Sum 3 end FixVecMain The commands to compile and execute FixVec c and FixVecMain p hostname cc c FixVec c hos...

Page 146: ... i Sum V i The Pascal main program UniVecMain p 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 var Sum integer external c begin V 0 7 V 1 8 V 2 9 UniVec V 2 Sum writeln Sum end UniVecMain The commands to compile and execute UniVec c and UniVecMain p hostname cc c UniVec c hostname pc calign UniVec o U...

Page 147: ...r each dimension except the last one Chapter 8 The FORTRAN Pascal Interface has an example of multidimensional conformant array passing The following example uses a single dimension array The C function IntCA c void IntCA int a int lb int ub int k for k 0 k ub lb k a k 4 The Pascal main program IntCAMain p Note that what Pascal passes as s is received in C as a lb ub program IntCAMain output var s...

Page 148: ...ecords 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 commands to compile and execute IntCA c and IntCAMain p host...

Page 149: ...ram StruChrMain output type TVarLenStr record nbytes integer a array 0 25 of char end var vls TVarLenStr i integer procedure StruChr var vls TVarLenStr external c begin StruChr vls write string for i 0 to vls nbytes 1 do write vls a i writeln writeln length vls nbytes end StruChrMain The commands to compile and execute StruChr c and StruChrMain p hostname cc c StruChr c hostname pc calign StruChr ...

Page 150: ...Following are some examples The C function VarRec c struct vlr char tag union struct char ch1 ch2 a_var struct char flag b_var struct int ALIGN c_var var_part void VarRec struct vlr x if x var_part a_var ch1 a x var_part a_var ch2 Z ...

Page 151: ... written in another language This keyword generally causes everything to be passed by reference The Pascal main program VarRecMain p program VarRecMain type vr record case tag char of a ch1 ch2 char b flag boolean K ALIGN integer end var x vr procedure VarRec var d vr external c begin x tag a x ch1 a x ch2 b VarRec x writeln x ch2 end VarRecMain The commands to compile and execute VarRec c and Var...

Page 152: ...ude stdio h void for_C char s int len int i for i 0 i len i putchar s i putchar n void for_NonPascal char s int len int i for i 0 i len i putchar s i putchar n The Pascal main program NonPasMain p program NonPasMain var s string procedure for_C var s string len integer external c procedure for_NonPascal var s string len integer nonpascal begin s Hello from Pascal for_C s 18 for_NonPascal s 18 end ...

Page 153: ...if necessary Simple Types With value parameters simple types match as in the following example The C function SimVal c void SimVal char t char f char c short si int i float sr double r int reply reply 0 if t reply 01 if f reply 010 if c z reply 0100 if si 9 reply 01000 if i 9 reply 010000 if sr float 9 9 reply 0100000 if r 9 9 reply 01000000 ...

Page 154: ... SimValMain p program SimVal output var t boolean true f boolean false c char z si integer16 9 i integer 9 sr shortreal 9 9 r double 9 9 args integer procedure SimVal t f boolean c char si integer16 i integer sr shortreal r double var Reply integer external c begin SimVal t f c si i sr r args writeln args args 6 oct end SimVal The commands to compile and execute SimVal c and SimValMain p hostname ...

Page 155: ...l main program RetRealMain p program RetRealMain var r s real function RetReal var x real real external c begin r 2 0 s RetReal r writeln r 4 1 s 4 1 end RetRealMain The commands to compile and execute RetReal c and RetRealMain p hostname cc c RetReal c hostname pc RetReal o RetRealMain p hostname a out 2 0 3 0 The C function ProcPar c include string h void proc_c void p a pointer to procedure arg...

Page 156: ... Pascal procedure proc_pas The C 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 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 pr...

Page 157: ...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 GloVar p var Year integer procedure GloVar begin Year 2001 end GloVar The C main program GloVar...

Page 158: ...name pc c GloVar p hostname cc GloVar o GloVarMain c hostname a out 2001 The C procedure UseFilePtr c include stdio h void UseFilePtr FILE ptr Write to the file fprintf ptr 1 Passing the file descriptor n fprintf ptr 2 and writing information n fprintf ptr 3 to a file n The Pascal main program UseFilePtrMain p program UseFilePtrMain var f text cfile univ_ptr procedure UseFilePtr cf univ_ptr extern...

Page 159: ...ands to compile and execute UseFilePtc c and UseFilePtrMain p hostname cc c UseFilePtr c hostname pc UseFilePtr o UseFilePtrMain p hostname a out hostname cat myfile data 1 Passing the file descriptor 2 and writing information 3 to a file ...

Page 160: ...136 Pascal 4 0 User s Guide 6 ...

Page 161: ...king with the Pascal runtime support library libpc On the Solaris 1 x environment if you use pc to link you must add the lc option The calign option causes pc to use data formats for aggregate objects similar to those in C Sample Interface page 137 Compatibility of Types for C and Pascal page 138 C Name Encoding page 138 Procedure Calls C Pascal page 138 Procedure Calls Pascal C page 155 Global Va...

Page 162: ...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 For brevity you can also combine extern C with the definition of the function as in Procedure Calls C Pascal Following are examples that illustrate how a C main program calls a Pascal procedure Included in each example are the Pascal procedure the C main program and t...

Page 163: ...n describes how they work with Pascal The C main program SampMain cc include stdio h extern C void Samp int double int main void int i double d Samp i d printf d 3 2f n i d The commands to compile and execute Samp p and SampMain cc c hostname pc c Samp p hostname CC Samp o SampMain cc lpc hostname a out 7 3 14 ...

Page 164: ...Without the xl option simple types match as in the following example The Pascal procedure SampRef in the file Samp p procedure SamRef var t f boolean var c char var i integer var s integer16 var r shortreal var d real begin t true f false c z i 9 s 9 r 9 9 d 9 9 end ...

Page 165: ...program SamRefMain cc include stdio h extern C void SamRef char char char int short float double int main void char t f c int i short s float r double d SamRef t f c i s r d printf 08o 08o c d d 3 1f 3 1f n t f c i s r d The commands to compile and execute SamRef p and SamRefMain cc hostname pc c SamRef p hostname CC SimRef o SamRefMain cc lpc hostname a out 00000001 00000000 z 9 9 9 9 9 9 ...

Page 166: ...tring types are arrays The C counterpart to the Pascal varying type is a structure Here is an example The Pascal procedure StrRef p 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 ...

Page 167: ...truct TVarLenStr vls char s10 10 s80 80 s25 25 vls NBytes 0 StrRef s10 s80 vls strncpy s25 vls a vls NBytes printf s10 s n s80 s n s25 s n s10 s80 s25 printf strlen s25 d n strlen s25 The commands to compile and execute StrRef p and StrRefMain cc hostname pc c StrRef p hostname CC StrRef o StrRefMain cc lpc hostname a out s10 abcdefghi s80 abcdefghijklmnopqrstuvwxyz s25 varstr strlen s25 6 ...

Page 168: ... integer begin Sum 0 for i 0 to 8 do Sum Sum V i end The C main program FixVedMain cc include stdio h extern C void FixVec int int int main void int Sum static int a 1 2 3 4 5 6 7 8 9 FixVec a Sum printf d n Sum The commands to compile and execute FixVec p and FixVecMain cc hostname pc c FixVec p hostname CC FixVec o FixVecMain cc lpc hostname a out 45 ...

Page 169: ...e illustrates this point The string Sunday only gets through to the C main program when you compile the Pascal routine using the calign option The Pascal procedure DaysOfWeek p type TDay array 0 8 of char TWeek array 0 6 of TDay TYear array 0 51 of TWeek procedure DaysOfWeek var Y TYear begin Y 1 1 Sunday end The C main program DaysOfWeekMain cc include stdio h extern C void DaysOfWeek char 52 7 9...

Page 170: ...c lpc hostname a out Day The commands to compile and execute DaysOfWeek p and DaysOfWeekMain cc withthe calign option hostname pc c calign DaysOfWeek p hostname CC DaysOfWeek o DaysOfWeekMain cc lpc hostname a out Day Sunday The Pascal procedure StruChr p It is safer for the Pascal procedure to explicitly provide the null byte and include it in the count before the string is passed to C type TLenS...

Page 171: ...id StruChr TVarLenStr int main void struct TVarLenStr vls char s25 25 vls NBytes 0 StruChr vls strncpy s25 vls a vls NBytes printf s25 s n s25 printf strlen s25 d n strlen s25 The commands to compile and execute StruChr p and StruChr cc hostname pc c StruChr p hostname CC StruChr o StruChrMain cc lpc hostname a out s25 St Petersburg strlen s25 13 ...

Page 172: ...cedure DayWeather p 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 W 1 TWeather Sunny WeatherSize 5 end ...

Page 173: ... string h struct TDayRec char TDay 9 char TWeather 21 extern C void DayWeather TDayRec 2 int int main void struct TDayRec dr 2 int NBytes char s25 25 char t25 25 NBytes 0 DayWeather dr NBytes strncpy s25 dr 1 TDay 6 printf day s n s25 strncpy t25 dr 1 TWeather NBytes printf weather s n t25 ...

Page 174: ... Pascal routine without the calign option the program does not work correctly hostname pc c DayWeather p hostname CC DayWeather o DayWeatherMain cc lpc hostname a out day weather Sun Compile with the calign option The program now works correctly hostname pc calign c DayWeather p hostname CC DayWeather o DayWeatherMain cc lpc hostname a out day Sunday weather Sunny ...

Page 175: ...procedure SimVal p procedure SimVal t f boolean c char si integer16 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 ...

Page 176: ...alMain cc include stdio h extern C void SimVal char char char short int float double int 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 r args printf args 07o n args return 0 The commands to compile and execute SimVal p and SimVal cc hostname pc c SimVal p hostname CC SimVal o SimValMain cc lpc hostname a out args 111111 ...

Page 177: ...p function RetReal r real real begin RetReal r 1 end The C main program RetRealMain cc include stdio h extern C double RetReal double int main void double r s r 2 0 s RetReal r printf f n s The commands to compile and execute RetReal p and RetRealMain cc hostname pc c RetReal p hostname CC RetReal o RetRealMain cc lpc hostname a out 3 000000 ...

Page 178: ...tRealMain cc include stdio h include math h extern C float RetShortReal float int main void float r s r 2 0 s RetShortReal r printf 8 6f n s The commands to compile and execute RetShortReal p and RetRealMain cc hostname pc c RetShortReal p hostname CC RetShortReal o RetShortRealMain cc lpc hostname a out 3 000000 The Pascal function IO p procedure IO begin writeln Hello Pascal St Petersburg end ...

Page 179: ...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 main program IOMain cc include stdio h extern C void IO int main void IO printf Hello C n The commands to compile and execute IO p and IOMain cc hostname pc c IO p hostname CC IO o IOMain cc lpc hostname a out Hello Pascal St Petersburg...

Page 180: ...ide 7 Simple Types Passed by Reference Simple types pass in a straightforward manner as follows The C function SimRef cc extern C void SimRef char t char f char c int i short s float r double d t 1 f 0 c z i 9 s 9 r 9 9 d 9 9 ...

Page 181: ...f boolean c char i integer s integer16 r shortreal d real procedure SimRef var t f boolean var c char var i integer var s integer16 var r shortreal var d real external C begin SimRef t f c i s r d writeln t f 6 c 2 i 2 s 2 r 4 1 d 4 1 end The commands to compile and execute SimRef cc and SimRefMain p hostname CC c SimRef cc hostname pc SimRef o SimRefMain p hostname a out true false z 9 9 9 9 9 9 ...

Page 182: ... See the following example The C function SimVal cc extern C void SimVal char t char f char c short si int i float sr double r int Reply Reply 0 if t Reply 01 if f Reply 010 if c z Reply 0100 if si 9 Reply 01000 if i 9 Reply 010000 if sr float 9 9 Reply 0100000 if r 9 9 Reply 01000000 ...

Page 183: ...t boolean true f boolean false c char z si integer16 9 i integer 9 sr shortreal 9 9 r real 9 9 args integer procedure SimVal t f boolean c char si integer16 i integer sr shortreal r real var Reply integer external C begin SimVal t f c si i sr r args writeln args args 7 oct end The commands to compile and execute SimVal cc and SimValMain p hostname CC c SimVal cc hostname pc SimVal o SimValMain p h...

Page 184: ...eturn x 1 0 The Pascal main program RetRealMain p program RetRealMain output var r s real function RetReal var x real real external C begin r 2 0 s RetReal r writeln r 4 1 Return s 4 1 end The commands to compile and execute RetReal cc and RetRealMain p hostname CC c RetReal cc hostname pc RetReal o RetRealMain p hostname a out 2 0 Return 3 0 ...

Page 185: ...ple The Pascal procedure GloVar p var Year integer procedure GloVar begin Year 1995 end The C main program GloVarMain cc include stdio h extern C void GloVar int Year int main void Year 2042 GloVar printf d n Year The commands to compile and execute GloVar p and GloVarMain cc hostname pc c GloVar p hostname CC GloVar o GloVarMain cc lpc hostname a out 1995 ...

Page 186: ...E ptr fprintf ptr 1 n fprintf ptr 2 n fprintf ptr 3 n The C main program UseFilePtrMain p program UseFilePtrMain output 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 execute UseFilePtr cc and UseFilePtrMain p hostname CC c UseFilePtr cc hostname pc UseFilePtr o UseFilePtrMain p host...

Page 187: ...ule you must explicitly bring in the runtime library on the command line For example you must use the compiler options lpfc and lpc 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 lpc option includes the Pascal object library libpc Compiler Mixed Language Programs page 163 ...

Page 188: ...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 Table 8 1 lists the default sizes and alignments of compatible types for...

Page 189: ...ouble double precision 8 8 longreal double precision 8 8 real double precision 8 8 single real 4 4 shortreal real 4 4 integer16 integer 2 2 2 integer32 integer 4 4 4 integer integer 4 4 4 128 127 logical 1 byte or character 1 1 boolean logical 1 byte or character 1 1 alfa character 10 10 1 char character 1 1 string character 80 80 1 varying n of char structure v integer 4 character n end structure...

Page 190: ... 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 are several incompat...

Page 191: ... 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 Pascal passes all parameters by value un...

Page 192: ...ase with a trailing underscore _ This format is required to match the conventions of the FORTRAN compiler var parameters are used to match FORTRAN defaults procedure samp_ var i integer var r real begin i 9 r 9 9 end samp_ 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 _ integer i double...

Page 193: ...c z i 9 r 9 9 si 9 sr 9 9 end simvar_ The FORTRAN main program SimVarmain f logical 1 t f character c integer 4 i double precision d integer 2 si real sr call SimVar t f c i d si sr write L2 L2 A2 I2 F4 1 I2 F4 1 t f c i d si sr stop end The commands to compile and execute SimVar p and SimVarmain f hostname pc c SimVar p hostname f77 SimVar o SimVarmain f lpfc lpc SimVarmain f MAIN hostname a out ...

Page 194: ...FORTRAN counterpart to the Pascal varying is a structure By default FORTRAN passes all by reference The Pascal procedure StrVar p type varstr varying 25 of char procedure strvar_ var a alfa var s string var v varstr begin a abcdefghij s abcdefghijklmnopqrtstuvwxyz v oyvay end strvar_ The FORTRAN main program StrVarmain f structure VarLenStr integer nbytes character a 25 end structure record VarLen...

Page 195: ...tname f77 StrVar o StrVarmain f lpfc lpc StrVarmain f MAIN hostname a out s10 abcdefghij s80 abcdefghijklmnopqrtstuvwxyz s25 oyvay The Pascal procedure FixVec p 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 end fixvec_ The FORTRAN main program FixVecmain f integer Sum integer a 9 data a 1 2 3 4 5 6 7 8 ...

Page 196: ...ds to compile and execute FixVec p and FixVecmain f hostname pc c FixVec p hostname f77 FixVec o FixVecmain f lpfc lpc hostname a out FixVecmain f MAIN 45 The Pascal procedure UniVec p which defines a 10 element array type VecTyp array 0 9 of integer procedure univec_ in V univ VecTyp var Last integer var Total integer var i integer begin Total 0 for i 0 to Last do Total Total V i end univec_ The ...

Page 197: ... 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 commands to compile and execute UniVec p and UniVecmain f hostname pc c UniVec p hostname f77 UniVec o UniVecmain f lpfc lpc UniVecmain f MAIN hostname a out 24 function ip var x array lb ub integer of real r...

Page 198: ...he FORTRAN main program IntCAmain f integer k integer s 0 2 data s 0 0 0 call IntCA s VAL 0 VAL 2 do k 0 2 write I1 s k end do stop end The commands to compile and execute IntCA p and IntCAmain f hostname pc c IntCA p hostname f77 IntCA o IntCAmain f lpfc lpc IntCAmain f MAIN hostname a out 0 1 2 The Pascal procedure ChrCA p Pascal passes the bounds by value procedure chrca_ var a array lb ub inte...

Page 199: ... 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 main program ChrCAmain f character s 16 data s this is a string call ChrCA s VAL 0 VAL 15 write A s stop end The commands to compile and execute ChrCA p and CharCAmain f hostname pc c ChrCA p hostname f77 ChrCA o ChrCAmain f lpfc lpc ChrCAm...

Page 200: ... v lenstr begin v chrstr oyvay v nbytes 5 end struchr_ The FORTRAN main program StruChrmain f structure VarLenStr integer nbytes character a 25 end structure record VarLenStr vls character s25 25 vls nbytes 0 Call StruChr vls s25 1 5 vls a 1 vls nbytes write 1 s25 1 format s25 A stop end The commands to compile and execute Struchr p and StruChrmain f hostname pc c StruChr p hostname f77 StruChr o ...

Page 201: ...es be constructed although there is some variation with architecture and sometimes you need to adjust the alignment The Pascal procedure VarRec p type vr record case tag char of a ch1 ch2 char b flag boolean K ALIGN integer end procedure varrec_ var Rec vr begin if Rec ch1 a then Rec ch2 Z end VarRec p ...

Page 202: ...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 ch1 a VRec var_rec a_rec ch2 b call varrec VRec write VRec var_rec a_rec ch2 stop end The commands to compile and execute VarRec p and VarRecmain f without...

Page 203: ... a minimum of 16 bytes of storage The Pascal procedure IntSetVar p which has an intset of the elements 1 3 7 8 procedure intsetvar_ var s intset begin s 1 3 7 8 end intsetvar_ The FORTRAN main program IntSetVarmain f 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 o3 1x octal word i2 write 110 001 010 binary word 8 write 876 543 210 bit nos word 8 st...

Page 204: ... match The commands to compile and execute IntSetVar p and IntSetVarmain f The output of this example depends on the architecture of your machine hostname pc c IntSetVar p hostname f77 IntSetVar o IntSetVarmain f lpfc lpc IntSetVarmain f MAIN hostname a out 0 octal word 5 0 octal word 6 0 octal word 7 612 octal word 8 110 001 010 binary word 8 876 543 210 bit nos word 8 ...

Page 205: ... to one if t then reply 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 SimValmain f logical 1 t f character c integer 4 i double precision d integer 2 s integer 4 args data t true f false c z i 9 d 9 9 s 9 call SimVal VAL t VAL f VAL c VAL i VAL d VAL s args...

Page 206: ...ue it cannot pass strings of characters fixed arrays or univ arrays by value Conformant Arrays Although 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 ...

Page 207: ... is a string call ChrCA s VAL 0 VAL 15 write A s stop end The commands to compile and execute ChrCAx p and ChrCAmain f hostname pc c ChrCAx p hostname f77 ChrCAx o ChrCAmain f lpfc lpc ChrCAmain f MAIN hostname a out This is a string The Pascal procedure PassPtr p In the Pascal procedure statement the name must be all in lowercase with a trailing underscore _ type PtrInt integer PtrReal real proce...

Page 208: ...he FORTRAN main program the name is converted to lowercase Uppsercase is ignored 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 iPtr dPtr write i2 f4 1 i d stop end The commands to compile and execute PastPtr p and PassPtrmain f hostname pc c PassPtr p hostname f77 PassPtr o PassPtrmain f lpfc lpc PassPtrm...

Page 209: ...alls Pascal FORTRAN This section parallels Procedure Calls FORTRAN Pascal on page 168 The comments and restrictions given in that section apply here also The Pascal function RetReal p function retreal_ var x real real begin retreal_ x 1 end retreal_ The FORTRAN main program RetRealmain f double precision r s RetReal r 2 0 s RetReal r write 2f4 1 r s stop end The commands to compile and execute Ret...

Page 210: ...erence the FORTRAN default Simple Types Simple types pass in a straightforward manner as follows The FORTRAN subroutine SimVar f subroutine SimVar t f c i d si sr logical 1 t f character c integer i double precision d integer 2 si real sr t true f false c z i 9 d 9 9 si 9 sr 9 9 return end ...

Page 211: ...har i integer r real si integer16 sr shortreal procedure simvar var t f boolean var c char var i integer var r real var si integer16 var sr shortreal external fortran begin simvar t f c i r si sr writeln t f 6 c 2 i 2 r 4 1 si 2 sr 4 1 end SimVarmain The commands to compile and execute SimVar p and SimVarmain p hostname f77 c SimVar f SimVar f simvar hostname pc SimVar o SimVarmain p lpfc lF77 hos...

Page 212: ...x 5 data ax abcdefghij sx abcdefghijklmnopqrstuvwxyz vx oyvay s10 1 10 ax 1 10 s80 1 80 sx 1 80 vls a 1 5 vx 1 5 vls nbytes 5 return end The Pascal main program StrVarmain p program StrVarmain output type varstr varying 25 of char var a alfa s string v 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 ...

Page 213: ...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 describ...

Page 214: ... var prompt string length integer32 external begin writeln Starting s Trio Jeepy mygrout_ s 8 writeln Ending end The FORTRAN subroutine mygrout f subroutine MyGrout N character N write 6 N return end The commands to compile and run this program hostname pc g c sun pas hostname f77 g sun o mygrout f lpc mygrout f mygrout hostname a out Starting Trio Jee Ending ...

Page 215: ...Sum V i return end The Pascal main program FixVecmain p 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 The commands to compile and execute FixVec f and FixVecmain p hostname f77 c FixVec f FixVec f fixvec hostname pc FixVec o FixVec...

Page 216: ...ne 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 The Pascal main program UniVecmain p program UniVec type VecTyp array 0 9 of integer procedure univec var V univ VecTyp in Last integer var Sum integer external fortran var Sum integer V array 0 2 of integer begin V 0 7 V 1 8 V 2 9 univec V 2 Sum writeln Sum end UniVec ...

Page 217: ...Arrays Pascal conformant array parameters are not compatible if Pascal calls FORTRAN The commands to compile and execute UniVec f and UniVecmain p hostname f77 c UniVec f UniVec f univec hostname pc UniVec o UniVecmain p lpfc lF77 hostname a out 24 ...

Page 218: ...teger nbytes character a 25 end structure record VarLenStr vls vls a 1 5 oyvay vls nbytes 5 return end The Pascal main program StruChrmain p program StruChrmain 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 ...

Page 219: ...riant records There is some variation with architecture and sometimes you need to adjust the alignment The commands to compile and execute StruChr f and StruChrmain p hostname f77 c StruChr f StruChr f struchr hostname pc StruChr o StruChrmain p lpfc lF77 hostname a out v chrstr oyvay v nbytes 5 ...

Page 220: ... VarRec VRec structure a_var character ch1 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 if VRec var_rec a_rec ...

Page 221: ...m VarRecmain type vr record case tag char of a ch1 ch2 char b flag boolean K ALIGN integer end var Rec vr procedure varrec var d vr external fortran begin Rec tag a Rec ch1 a Rec ch2 b varrec Rec writeln Rec ch2 end VarRecmain The commands to compile and execute VarRec f and VarRecmain p without xl hostname f77 c VarRec f VarRec f varrec hostname pc VarRec o VarRecmain p lpfc lF77 hostname a out b...

Page 222: ...ase with no underscore _ The FORTRAN subroutine SimVal f subroutine SimVal t f c i d s reply logical 1 t f character c 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 ...

Page 223: ...r procedure simval t f boolean c char i integer r real s integer16 var reply integer external fortran begin simval t f c i r s args writeln args args 6 oct If nth digit 1 arg n OK end SimVal The commands to compile and execute SimVal f and SimValmain p hostname f77 c SimVal f SimVal f simval hostname pc SimVal o SimValmain p lpfc lF77 hostname a out args 111111 If nth digit 1 arg n OK ...

Page 224: ...tr integer i double precision d pointer iPtr i dPtr d i 9 d 9 9 return end The Pascal main program PassPtrmain p In the Pascal program where it calls the FORTRAN subroutine the name must be in lowercase program PassPtrmain type PtrInt integer PtrReal real var i integer 0 r real 0 0 iP PtrInt rP PtrReal procedure passptr var xiP PtrInt var xrP PtrReal external fortran begin iP addr i rP addr r pass...

Page 225: ... commands to compile and execute PassPtr f and PassPtrmain p hostname f77 c PassPtr f PassPtr f passptr hostname pc PassPtr o PassPtrmain p lpfc lF77 hostname a out 9 9 9 The FORTRAN function RetReal f double precision function retreal x retreal x 1 0 return end The Pascal main program RetRealmain p program retrealmain var r s real function retreal x real real external fortran begin r 2 0 s retrea...

Page 226: ...RAN real type without xl Routines as Parameters If the passed procedure is a top level procedure write it as follows The commands to compile and execute RetReal f and RetRealmain p hostname f77 c RetReal f RetReal f retreal hostname pc RetReal o RetRealmain p lpfc lF77 hostname a out 2 0 3 0 The FORTRAN subroutine PassProc f subroutine PassProc r s prcdr real r s external prcdr call prcdr r s retu...

Page 227: ...cedures 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 Pascal main program 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 real be...

Page 228: ... 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 ...

Page 229: ...mmon 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 of a 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 Compiler Syntax Errors page 2...

Page 230: ...nd 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 delimiter 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 ...

Page 231: ...ases the recovery makes no attempt to determine which identifier or what number should be inserted Thus these are considered fatal syntax errors The Pascal program synerr p which uses as an exponentiation operator program synerr_example output var i j are integer begin for j 1 to 20 begin write j i 2 j writeln i end end synerr_example synerr p produces a fatal syntax error when you compile it beca...

Page 232: ...correct uses in the same way it summarizes uses of undeclared variables Expected Symbols and Malformed Constructs 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 ...

Page 233: ...ine 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 malformed statement at the point of assignment hostname pc synerr2 p Mon Feb 13 11 02 04 1995 synerr2 p 3 integer a 10 e 18480 In...

Page 234: ... 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 Since Pascal is a strongly typed languag...

Page 235: ...ned 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 If the type of an argument is wrong you receive a message similar to th...

Page 236: ...t 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 diagnost...

Page 237: ...eln hue s and color s end expr_example hostname pc expr p Mon Feb 13 13 36 51 1995 expr p E 13050 line 16 Constant string too long E 20070 line 17 Left operand of and must be Boolean not set E 25550 line 18 expression has invalid type E 20030 line 18 Cannot mix sets with integers and reals as operands of E 20240 line 19 files may not participate in comparisons E 20230 line 20 pointers and integers...

Page 238: ...e same type identifier Therefore the following two variables have different types even though the types look the same and have the same characteristics The assignment x y produces the following diagnostic messages x record a integer b char end y record a integer b char end Mon Feb 13 14 22 46 1995 inchar p E 25170 line 12 Type clash non identical record types 25560 Type of expression clashed with ...

Page 239: ...nt then works Unreachable Statements Pascal flags unreachable statements Such statements usually correspond to errors in the program logic as shown in the following example type r record a integer b char end var x r y r x y record a integer b char end The Pascal program unreached p program unreached_example output label 1 begin goto 1 writeln Unreachable 1 writeln Reached this end unreached_exampl...

Page 240: ...s 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...

Page 241: ...y 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 rec...

Page 242: ...ame Could not open file filename Could not remove file filename Could not reset file filename Could not seek file filename Could not write to file filename File name too long maximum of number exceeded filename File table overflow maximum of number exceeded filename Line limit exceeded filename Non positive format widths are non standard filename Overflow on integer read filename Tried to read pas...

Page 243: ...utput Floating point division by zero Floating point operand is signaling Not A Number Floating point overflow Floating point underflow Illegal argument of number to trunc Inexact floating point result Integer divide by zero Integer overflow Internal error in enumerated type read Invalid floating point operand Label of number not found in case Negative argument of number to sqrt Non positive argum...

Page 244: ... limit of number exceeded Subrange or array subscript is out of range Sun FPA not enabled Unknown SIGFPE code Unordered floating point comparison Value of number out of set bounds Varying length string index number is out of range exp number yields a result that is out of the range of reals i number Bad i to pack a i z i number Bad i to unpack z a i pack a i z z has number more elements than a sub...

Page 245: ...Reilly Associates Inc 1990 The sections in this chapter are Note Support for the XView toolkit will not be provided in future releases of Pascal Overview 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 wit...

Page 246: ...ed 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 ...

Page 247: ...elationship illustrated in Figure 10 1 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 itsel...

Page 248: ..._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...

Page 249: ...bute requested For example 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 s...

Page 250: ...h should be passed to xv_destroy when you are finished with it Handles 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 Data Types 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 S...

Page 251: ... 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 pro...

Page 252: ...st be converted to the Pascal type boolean Table 10 1 shows you how to convert C declarations to Pascal 1 Defined in stddefs_p h Table 10 1 C Declarations to Pascal Declarations C Pascal int integer subrange or numeric constant unsigned unsigned subrange or numeric constant1 short integer16 subrange or numeric constant unsigned short unsigned16 subrange or nonnegative numeric constant char char or...

Page 253: ...er of characters inserted invoke it as an integer function 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 var textsw Tex...

Page 254: ...lolgx lX11 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 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_c...

Page 255: ...rame Frame base_panel Panel button Panel_button_item menu Menu frame_label string button_label string option1 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 option1 option1 O...

Page 256: ...a out base_frame xv_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 option1 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_...

Page 257: ... 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 constants 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 ...

Page 258: ...s the contents of the math libraries Table 11 1 Contents of Math Libraries Algebraic functions Rootsm Euclidean distancem s Transcendental functions Elementary transcendental functions Trigonometric functions Trigonometric functions of radian argumentsm Trigonometric functions of degree arguments s Trigonometric functions scaled in Pi s Trigonometric functions with double precision Pi s Hyperbolic...

Page 259: ...ion version are formed by adding f to the names of the double precision version Random number generators Additive pseudo random generatorss Linear pseudo random generatorss Random number shufflerss IEEE support functions IEEE functionsm IEEE testm IEEE valuess IEEE suns Control flagss Floating point trap handling IEEE handlings Handling for specific SIGFPE codes in libc Error handling functionm Da...

Page 260: ...d ieeee_retrospective program TestLibm output include math_p h var d0 d1 d2 double f0 f1 f2 single begin d0 0 0 d1 1 0 d2 2 0 f0 0 0 f1 1 0 f2 2 0 writeln Trigonometric functions writeln sin d0 writeln sinf f0 sincos M_PI_2 d1 d2 writeln d1 d2 sincosf M_PI_2 f1 f2 writeln f1 f2 writeln Exponential logarithm power writeln exp d1 writeln log d1 writeln pow d1 d1 writeln expf f1 writeln logf f1 write...

Page 261: ... and maximum positive floating point numbers are provided by special functions described in the ieee_values 3M man page Another example follows program TestIEEEFunctions output include math_p h var d1 double 1 0 d2 double 2 0 i1 integer 1 begin writeln IEEE functions writeln ilogb d1 writeln isnan d1 writeln copysign d1 d2 writeln fabs d1 writeln fmod d1 d1 writeln nextafter d1 d1 writeln remainde...

Page 262: ...ing 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 pr...

Page 263: ...or the operation about to be performed program TestRandom output include math_p h var n integer 100 i integer ilb Lower bound iub integer Upper bound ia 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 to n do writeln ia i writeln Integer additive random number generator ilb minint iub maxint i_add...

Page 264: ...n occurs whenever there is untrapped overflow or untrapped underflow Math Library Exception Handling Function matherr 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 struc...

Page 265: ...TLOSS Total loss of significance PLOSS Partial loss of significance program TestMatherr output include math_p h function matherr var info exception integer begin case info kind of DOMAIN begin change sqrt to return sqrt arg1 not NaN if substr info name 1 length sqrt sqrt then begin info retval sqrt info arg1 matherr 1 No exception message will be printed end end otherwise matherr 0 end end begin w...

Page 266: ... the recommended interface to Query or set rounding direction mode Query or set rounding precision mode Examine clear or set accrued exception flags program TestIEEEHandler output include math_p h 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 d...

Page 267: ...d exceptions is done by a call as shown in the following Pascal program program TestIEEEFlags output include math_p h var FlAction FlMode FlIn string FlOut string_pointer Zero integer 0 begin writeln sqr 1 Invalid operation writeln 1 Zero Division by zero writeln exp 709 8 Overflow writeln exp 708 5 Underflow writeln log 1 1 Inexact FlAction clear FlMode exception FlIn all writeln ieee_flags FlAct...

Page 268: ...244 Pascal 4 0 User s Guide 11 ...

Page 269: ...ion of cpp 1 see the Solaris documentation cppas The cppas preprocessor handles the Pascal conditional variables and compiler directives You call cppas using the xl option Conditional Variables A conditional variable is defined when it appears in a var directive otherwise it is undefined In addition we predefine These variables are not predefined when you use s0 s1 V0 or V1 __sun __SVR4 sparc __sp...

Page 270: ...var one two enable two Table A 1 cppas Compiler Directives Compiler Directive Description config Sets a special predefined conditional variable with a value of either true or false debug Instructs pc to compile this line of code when you use the cond compiler directive else If expression in if expression then is false the compiler skips over the then part and executes the else part instead elseif ...

Page 271: ...g the current Pascal source file if When the compiler encounters a if expression then directive it evaluates expression If expression is true pc executes the statements after then If expression is false pc skips over then ifdef Determines whether or not you previously defined a conditional variable in a var directive include Inserts the lines from the specified file into the input stream list Enab...

Page 272: ...writeln Begin program if one then writeln One is defined as a 2 elseif two then writeln Two is defined as b 2 elseif config then writeln Nothing is defined endif writeln End program end config_example The output when you compile config p without the config option hostname pc xl config p hostname a out Begin program End program The output when you define the variable one hostname pc xl config one c...

Page 273: ...er option cond causes pc to compile the lines in your program that begin with debug Without cond pc treats lines with debug as comments The output when you define two hostname pc xl config two config p hostname a out Begin program Two is defined as 32768 End program The output when you define foo hostname pc xl config foo config p Fri Mar 3 15 22 1995 config p Error CONFIG command argument foo was...

Page 274: ...rogram debug_example output This program demonstrates the use of the debug compiler directive begin writeln Hello how are you debug writeln Fine thank you end debug example The output when you compile debug p without the cond option hostname pc xl debug p hostname a out Hello how are you The output when you use cond hostname pc xl cond debug p hostname a out Hello how are you Fine thank you ...

Page 275: ...he Pascal program if_then_else p program if_then_else output var red begin if red then writeln It is red else writeln It is not red endif end The output when you compile if_then_else p without the config hostname pc xl if_then_else p hostname a out It is not red The output when you supply config with the argument red hostname pc xl config red if_then_else p hostname a out It is red ...

Page 276: ...provides an alternative action to the ifdef directive The Pascal program elseif p program elseif_example output This program demonstrates the use of the if then and elseif directives var blue red begin if blue then writeln The color is blue elseif red then writeln The color is red endif end elseif_example The output when you supply config with the argument blue hostname pc xl config blue elseif p ...

Page 277: ...s and or and not See the else listing for examples of expression Example The Pascal program ifdef p which first checks if bird1 has been defined If not it defines it with a var directive If bird1 has been defined the program checks whether or not it needs to define bird2 program ifdef_example output include bird h begin ifdef not bird1 then var bird1 elseifdef not bird2 then var bird2 endif if bir...

Page 278: ...directive or in the config option Conditional variables are false by default The include file bird h var a array 1 7 of char penguin b array 1 6 of char toucan var bird1 The output when you enable bird1 with the config option hostname pc xl config bird1 ifdef p hostname a out Bird two is a penguin The output when you enable bird2 with the config option hostname pc xl config bird2 ifdef p hostname ...

Page 279: ...ram enable p This example sets the conditional variable two to true which is equivalent to setting the config option to two on the command line program enable_example output This program demonstrates the use of the enable compiler directive var a integer b integer var one two enable two begin if one then a maxint writeln One is defined as a 2 endif if two then b minint writeln Two is defined as b ...

Page 280: ... program error p program error_example output This program demonstrates the use of the error compiler directive var arch begin if arch then writeln This is a SPARC computer else error Unknown architecture endif end error_example error p produces this error if you compile it without the config sparc option hostname pc xl error p Tue Feb 28 17 10 1995 error p Line 12 error Unknown architecture E Unk...

Page 281: ...ithin an if or ifdef construct it closes all if or ifdefs before it stops processing the current file Example The if Directive The if directive is a conditional branching directive Syntax if expression then end if The Pascal program exit_directive p program exit_directive output begin writeln Hello world end exit_directive exit Everything after the exit is ignored So you can put anything here The ...

Page 282: ...able 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 option 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 else listing on page 250 The ifdef Directive T...

Page 283: ...lude file Example See the example in The elseifdef Directive The include Directive The include directive inserts lines from the specified file in the input stream Syntax include filename Comments When cppas encounters the include directive it inserts the lines from the file name into the input stream Example The program unit include_prog p program include_prog include extern h begin global 1 write...

Page 284: ... proc include extern h procedure proc begin writeln From PROC global global global 1 end proc The include file include h var global integer procedure proc extern The commands to compile and execute ext_prog p and ext_mod p hostname pc xl include_prog p include_mod p include_prog p include_mod p Linking hostname a out From MAIN before PROC 1 From PROC 1 From MAIN after PROC 2 ...

Page 285: ... pri red yellow blue pos true false cap A Z dig 0 100 writeln There are card pri 4 primary colors writeln There are card pos 4 possibilities writeln There are card cap 4 capital letters writeln There are card dig 4 digits end list_example The include file types h type lowints 0 100 primary_colors set of red yellow blue possibilities set of boolean capital_letters set of A Z digits set of lowints v...

Page 286: ...hostname pc xl 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 include types h hostname a out There are 3 primar...

Page 287: ...tional variables for the preprocessor Syntax var var1 varN Comments A conditional variable is defined when it appears in a var directive otherwise it is undefined Example See the example under The config 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 warning string Comments pc produces an object f...

Page 288: ...use of the warning compiler directives var blue begin if blue then writeln The color is blue else warning Color not defined endif end warning_example The output when you compile warning p without the config option hostname pc xl warning p Fri Mar 3 15 03 1995 warning p Line 12 warning Color not defined w Architecture not defined ...

Page 289: ...tin function takes at least number arguments and at most number 10040 Built in function cannot be passed as a parameter 10050 argv takes two arguments 10060 argv s first argument must be an integer not type 10070 argv s second argument must be a string not type 10080 Argument to card must be a set not type 10090 flush takes at most one argument 10100 flush s argument must be a file not type 10110 ...

Page 290: ...ignored 10180 Argument to function must be of type type not type 10190 Second argument to function must be of type type not type 10200 First argument to function must be of type type not type 10210 Illegal argument to IN_RANGE 10220 Type clash in argument to IN_RANGE 10230 Illegal argument to ADDR 10240 Third argument to function must be of type type not type 10250 Argument to ADDR is a dynamicall...

Page 291: ...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 function takes no arguments 10410 function takes either zero or one argument 10420 function takes exactly one argument 10430 function s argument must be int...

Page 292: ...e only one argument 10540 Arguments to function 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 function expects one argument 10600 Argument to function must be a file not type 10610 function expects one or two arguments 10620 First argument to function must be a file not type ...

Page 293: ... must be a string not type 10730 linelimit expects two arguments 10740 linelimit s second argument must be an integer not type 10750 linelimit s first argument must be a text file not type 10760 page expects one argument 10770 Argument to page must be a text file not type 10780 Assert expects one or two arguments 10790 Second argument to assert must be a string not type 10800 pack expects three ar...

Page 294: ... 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 type s 11090 Varying size must be a constant 11100 Size of identifier is zero 11110 Character array lower bound 1 11120 Character array upper bound of 1 11130 function requires a to be an unpacked array not type 11140 functi...

Page 295: ...case label in record 11240 operation not allowed on records only allow and 11250 Variable in with statement refers to identifier not to a record 11260 Too many tag fields 11270 No variant case label value equals specified constant value 11280 Tag fields cannot be type s 11290 Bad variant constant 11300 variant required after case 12010 Assert expression must be Boolean not type s 12020 illegal tra...

Page 296: ...textfile 12130 Can t read type s from a text file 12140 Can t readln a non text file 12150 Oct hex allowed only on text files 12160 Write widths allowed only on text files 12170 Cannot write unpacked array to textfile 12180 Can t write type s to a text file 12190 Can t writeln a non text file 13010 constant identifier required 13020 Constant value cannot be evaluated at compile time 13030 Constant...

Page 297: ...clarations 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 14070 function has already been declared forward 14080 Unknown language identifier in EXTERN procedure declaration ignored 14090 Unresolved forward declaration of function 14100 identifier DEFINED but ...

Page 298: ...00 All variables should be declared in one var part 14210 public vars must be declared at outer block level 14220 Declarations may not be both STATIC and PUBLIC STATIC is ignored 14230 Declarations may not be both DEFINE and PRIVATE DEFINE is ignored 14240 Declarations may not be both EXTERN and PRIVATE EXTERN is ignored 14250 identifier was declared in a DEFINE cannot be STATIC 14260 identifier w...

Page 299: ... subrange descriptor used in illegal context 14380 Cannot initialize dynamic local variables 15010 File identifier listed in program statement but not declared 15020 File identifier listed in program statement but declared as a identifier 15030 File identifier listed in program statement but defined as identifier 15040 Files cannot be passed by value 15050 Files cannot be a component of identifier...

Page 300: ...rn type s 16050 Procedure function nesting too deep 16060 pcc_fvar no result for this function 16070 identifier is a class not a function 16080 Illegal function qualification 16090 compiler takes size of function 16100 Can t call identifier 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 i...

Page 301: ...tine identifier to non pascal routine identifier 16230 Can t call identifier 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 number out of range for this implementation 17050 Implementation restriction sets must be indexed by 16 bit quantities 1...

Page 302: ...riable is out of range 17160 Value of integer terminal assign to for loop variable is out of range 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 18050 Illegal character use the xl option to process compiler directives 18060 Illegal character 18070 unexpected EOF 18080 Point of error 18090 Parsing resumes 1810...

Page 303: ...ted options not identifier 18210 Unknown option ignored identifier 18220 Duplicate options specification identifier 18230 Unimplemented option ignored identifier 18240 identifier undefined on line number 18250 identifier improperly used on line number 18260 identifier is neither used nor set 18270 identifier is never used 18280 identifier is used but never set 18290 Length of external label for id...

Page 304: ...identifier not defined in correct block 18510 Label identifier redefined 18520 identifier is undefined 18530 allowed only on files and pointers not on type s 18540 Pascal uses for subscripting not 18550 Error occurred on qualification of identifier 18560 division by 0 18580 Variable required in this context 18590 Universal pointers may not be dereferenced 18600 Illegal format 18610 Unknown format ...

Page 305: ...18710 Bad arbitrary base integer 18720 Bad base number number number 18730 Digits required after decimal point 18740 Digits required before decimal point 18750 Digits required in exponent 18760 Space required between number and word symbol 18770 Character string delimiter is 18780 Unmatched for string 18790 Null string not allowed 18800 Invalid preprocessed file probably renamed as p Compile the o...

Page 306: ...ts with integers and reals as operands of type 20040 Operands of operator must be Boolean or Integer 20050 Left operand of must be integer or real not type 20060 Right operand of must be integer or real not type 20070 Left operand of operator must be Boolean not type 20080 Right operand of operator must be Boolean not type 20090 Left operand of operator must be integer not type 20100 Right operand...

Page 307: ...0 Strings not same length in operator comparison 20230 identifier s and identifier s cannot be compared operator was operator 20240 identifier s may not participate in comparisons 21010 Attempt to pass IN parameter to formal reference parameter 21020 Expression type clashed with type of value parameter identifier of identifier 21030 Expression given variable required for var parameter identifier o...

Page 308: ...given for formal class parameter identifier 21140 does not match type of formal class parameter identifier line number 21150 class parameter identifier of identifier line number 21160 does not match class parameter identifier of identifier line number 21170 Type of class parameter identifier of identifier line number 21180 does not match type of class parameter identifier of identifier line number...

Page 309: ...qualified 21290 Expression given class required for class parameter identifier 21300 Variable given class required for class parameter identifier 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 identifier should be passed as a var parameter 21350 Fields which select variant par...

Page 310: ...ory 22110 Ran out of hash tables 22120 Ran out of tree tables 22130 Out of space put_on_idlist 22140 out of tree space try simplifying 22150 out of temporary string space 23010 identifier is a non standard function 23020 identifier is a non standard procedure 23030 Two argument forms of reset and rewrite are non standard 23040 NIL values in const declaration are non standard 23050 Set constants in...

Page 311: ...nction 23150 OTHERWISE clause in case statements is non standard 23160 Ranges in case statements are non standard 23170 Transfer functions are non standard 23180 Reading scalars from text files is non standard 23190 Writing type s with two write widths is non standard 23200 Zero widths are non standard 23210 Oct and hex are non standard 23220 Writing type s to text files is non standard 23230 iden...

Page 312: ...tifier cannot be an element of a record 24040 For statement variable identifier may be illegally changed at line number 24050 For statement variable identifier must be declared in the block in which it is used 24060 For statement variable identifier cannot be type s 24070 Can t modify the for statement variable identifier in the range of the loop 24080 Incorrect control variable 24090 Type of init...

Page 313: ...er 24190 Maximum number of case selectors exceeded 24200 Cannot next not within a loop 24210 Goto label is into a structured statement 24220 Goto label from line number is into a structured statement 24230 Variable in with statement refers to type not to a record 24240 Maximum WITH nesting depth exceeded ignoring WITH variables 24250 Variable in with statement not correct 24260 cannot assign to lh...

Page 314: ...e 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 wh...

Page 315: ...rray with lower bound 1 25220 Type clash Non identical string types must be packed 25230 Type clash packed array with lower bound 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 ...

Page 316: ...y 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 constant type clashed with variant case selector type 25460 Ta...

Page 317: ...xpression clashed with type of variable in assignment 25570 Type of expression in if statement must be Boolean not type 25580 Type of transfer function does not match type of right side 25590 identifier is a class not a type as required 25600 Set type must be range or scalar not type 25610 Sets must have basetype with range number number 25620 Subrange type cannot contain a expression 25630 Scalar...

Page 318: ...ion 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 L...

Page 319: ...Customer Support 18330 NAME with no symbol table entry 18340 ir_symbol unknown class 18350 ir_leaf cannot take address of op identifier 18360 ir_leaf illegal leaf node op identifier 18370 ir_starg illegal STARG 18380 ir_exit no return label 18390 cannot take address of op identifier 18400 op identifier not implemented yet 18410 goal integer not defined for op operation 18570 wasted space number ...

Page 320: ...296 Pascal 4 0 User s Guide B ...

Page 321: ...g 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 glob...

Page 322: ...217 compiler directives 246 to 263 include 67 config 247 debug 27 249 else 250 elseif 251 elseifdef 252 enable 246 254 endif 255 error 255 exit 256 if 247 257 ifdef 255 257 258 include 259 263 list 260 nolist 262 slibrary 263 var 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 statem...

Page 323: ...ifferent languages 87 define statement 27 define declaration 83 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 ...

Page 324: ...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 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 opti...

Page 325: ...6 34 40 Ldirectory option to pc command 33 Level 0 standard Pascal 1 46 Level 1 standard Pascal 1 46 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...

Page 326: ... 66 order of processing options 23 out of memory error 217 output 10 to 13 P P option to pc command 36 38 p option to pc command 39 panics 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...

Page 327: ... pg option 39 PIC option 39 pic option 39 Qoption 40 qp option 40 Qpath option 40 Qproduce option 40 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 VO and V1 options 49 w option 49 xarch a option 49 xcache c option 53 xchip c option 54 xF option 55 xil...

Page 328: ...mmand 41 running a Pascal program 9 to 13 runtime errors 217 to 220 Rw option to pc command 41 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 ...

Page 329: ...ing variables 71 to 73 76 to 86 unreachable statements errors 215 unused item errors 216 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 var directive 247 258 263 variable conditional 27 246 define 82 initialization of and errors 216 ...

Page 330: ...ption 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 introduct...

Page 331: ...Index 307 ...

Page 332: ...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 SPARC...

Page 333: ......

Reviews: