Pascal 4.0 User’s Guide A Sun Microsystems, Inc. Business 2550 Garcia Avenue Mountain View, CA 94043 U.S.A. Part No.
1995 Sun Microsystems, Inc. 2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Portions of this product may be derived from the UNIX® system and from the Berkeley 4.
Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Pascal Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iv Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Renaming the Executable File . . . . . . . . . . . . . . . . . . . . . . . . 9 An Interactive Pascal Program . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents –c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 -calign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 –cg89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 –cg92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 -cond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
vi –L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 –l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 -Ldirectory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 -libmieee. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 –libmil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 –llib . . .
Contents -R path[:dir] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 -Rw. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 –S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 –s[level] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 –sb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
viii -xlibmieee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 -xlibmil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 -xlibmopt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 –xlicinfo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 –xMerge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 -xnolib . . . . . . . . . . . . .
Sharing Variables Between Units . . . . . . . . . . . . . . . . . . . . . . 71 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 5. Separate Compilation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Working with Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Using Program Units. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Using Module Units . . . . . . . . . . . . . .
x Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Parameters That Are Pointers to Procedures . . . . . . . . . . . . 131 Procedures and Functions as Parameters . . . . . . . . . . . . . . . . . . 132 Global Variables in C and Pascal . . . . . . . . . . . . . . . . . . . . . . . . . 133 File-Passing Between Pascal and C . . . . . . . . . . . . . . . . . . . . . . . 134 7. The C++–Pascal Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
General Parameter-Passing in FORTRAN and Pascal. . . . . . . . 167 Procedure Calls: FORTRAN-Pascal . . . . . . . . . . . . . . . . . . . . . . . 168 Variable Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Value Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Function Return Values. . . . . . . . . . . . . . . . . . . . . . . . . .
xii The scalar Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Procedure and Function Type Errors. . . . . . . . . . . . . . . . . . . 211 Scalar Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Expression Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Type Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Unreachable Statements . . . . . . . . . . . . . . . . . . . . . .
An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Sample Translation of an XView Function to Pascal . . . . . . 229 Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Menu Demo Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 11. Math Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Contents of the Math Libraries. . . . . . . . . . . .
xiv Pascal 4.
Figures Figure 3-1 Organization of Pascal Compilation. . . . . . . . . . . . . . . . . . . . . . 19 Figure 3-2 Options in Program Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Figure 10-1 A Sample Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xvi Pascal 4.
Tables Table 3-1 File Name Suffixes Recognized by Pascal . . . . . . . . . . . . . . . . . 20 Table 3-2 Options That Can Be Passed in Program Text . . . . . . . . . . . . . 21 Table 3-3 The -xarch Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Table 3-4 The -xcache Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Table 3-5 The -xchip Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xviii Table 10-1 C Declarations to Pascal Declarations . . . . . . . . . . . . . . . . . . . . 228 Table 11-1 Contents of Math Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Pascal 4.
Preface This manual describes the Pascal 4.0 compiler from SunSoft™. The purpose of this manual is to help you begin writing and compiling Pascal programs on a SPARCstation™. In a previous major release, this Pascal compiler also ran on Solaris 1.x. Some features remain in the documentation as being for Solaris 1.x only. The README file that accompanies the product contains other release-specific information, Note – All references to Pascal in this manual refer to the Pascal 4.
Audience This guide was prepared for software engineers who write Pascal programs on a SPARCstation. It assumes you are familiar with ISO standard Pascal and the Solaris™ operating system. Organization This guide contains the following chapters: xx • Chapter 1, “Introduction,” gives basic information about the Pascal compiler and related program development tools. • Chapter 2, “Pascal Programs,” describes how to write, compile, and run a Pascal program.
• Appendix B, “Error Messages,” lists all the error messages the compiler produces. This guide concludes with an index. Conventions Used in This Guide This guide contains syntax diagrams of the Pascal language in extended Backus-Naur Formalism (BNF) notation.
Shell Prompts in Command Examples The following table shows the default system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell. Table P-3 Shell Prompts Shell Prompt C shell prompt machine_name% C shell superuser prompt machine_name# Bourne shell and Korn shell prompt $ Bourne shell and Korn shell superuser prompt # Related Documentation This manual is designed to accompany the following documents: • The Pascal 4.
README Files The README default directory is: /opt/SUNWspro/READMEs. This directory contains the following files: • A Pascal 4.0 README, called pascal, that describes the new features, software incompatibilities, and software bugs • A floating-point white paper, “What Every Scientist Should Know About Floating-Point Arithmetic,” by David Goldberg, in PostScript™ format. The file is called floating-point.ps, and can be printed on any PostScriptcompatible printer that has Palatino font.
Table P-4 Documents in Hard Copy and in AnswerBook (Continued) Title Hard Copy On-Line Numerical Computation Guide X (AnswerBook) README X (CD-ROM) What Every Scientist Should Know About Floating-Point Arithmetic X (AnswerBook and CD-ROM) xxiv Pascal 4.
1 Introduction This chapter gives an overview of the features of Pascal, including compatibility, internationalization, and licensing. It contains the following sections: Standards page 1 Pascal Compiler page 2 Features page 2 Compatibility page 2 Text Editors page 3 Debuggers page 3 XView Toolkit page 3 Native Language Support page 3 Licensing page 5 Standards Pascal is a derivative of the Berkeley Pascal system distributed with UNIX® 4.2 BSD.
1 Pascal Compiler The name of the Pascal compiler is pc. If given an argument file name ending with .p or .pas, pc compiles the file and leaves the result in an executable file, called a.out by default.
1 Text Editors The operating system provides two main editors: • Text Editor—A window-based text editor that runs in the OpenWindows environment. Start this tool by typing textedit at the system prompt. • vi—The standard visual display editor that offers the capabilities of both a line and a screen editor. It also provides several commands for editing programs. For example: • The autoindent option provides white space at the beginning of a line. • The showmatch option shows matching parentheses.
1 Internationalization A product can support up to four levels of internationalization: • Level 1—Allows native-language characters (such as the a-umlaut). This is referred to as the 8-bit clean model because the eighth bit in each byte is used to represent native-language characters. • Level 2—Recognizes and displays international date and time formats, such as 26.07.90 in Italian; international decimal units, such as 1.234.567,89 in French; and international monetary units, such as 1.
1 If you reset your system locale to, for example, France, and rerun the program, the output is the same. Pascal does not replace the period with a comma, the French decimal unit. Locale You can change your application from one native language to another by setting the locale. For information on this and other native language support features, see the Solaris documentation on internationalization.
1 6 Pascal 4.
2 Pascal Programs This chapter cites two examples that illustrate how to compile and execute a program. It also explains how to use the traceback facility to find out why a program fails. The sections are: A Simple Pascal Program page 7 An Interactive Pascal Program page 10 Where Did My Program Fail? page 13 Building a program with SPARCompiler Pascal requires three steps: 1. Writing a program in Pascal using an editor and saving it in a file with a .p or .pas suffix 2. Compiling the .p or .
2 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. Compiling the Program Now compile the program with pc, the Pascal compiler, by typing at the system prompt: hostname% pc temp.
2 Running the Program To run the program, enter a.out at the prompt. The output of temp.p is then displayed: 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 41 5.00 42 5.56 43 6.11 44 6.67 45 7.22 46 7.78 47 8.33 48 8.89 49 9.44 50 10.00 Renaming the Executable File It is inconvenient to have the result of every compilation in a file called a.out. If such a file already exists, it is overwritten.
2 Now run the program by typing the name of the executable file. The output follows: hostname% temp Fahrenheit Celsius ---------------32 0.00 33 0.56 34 1.11 . . . . . . An Interactive Pascal Program In Pascal, the predefined file variable, input, is equivalent to the operating system standard input file, stdin. Similarly, the file variable, output, is equivalent to the standard output file, stdout. Following is a Pascal program that copies input to output.
2 Compiling the Program Use the pc command to compile the program and store it in the executable file copy. Here is the command format: hostname% pc -o copy copy.p Running the Program Because the standard files input and output default to the terminal, the program simply echoes each line you type. The program terminates when you type the end-of-file (Control-d) character at the beginning of a line. Try it: hostname% copy hello, are you listening? hello, are you listening? goodbye, I must go now.
2 Using the same program, but with the < operator to redirect input, you can print the file on the terminal: hostname% copy < data hello, are you listening? goodbye, I must go now. Using a File Name as a File Variable You can also redirect the output by listing the file as a file variable in the program statement. The Pascal library associates the file variable with a file of the same name. For example, copy2.
2 Assuming that the file data is still in the current directory, you can compile and run the program as follows: hostname% pc -o copy2 copy2.p hostname% copy2 hello, are you listening? goodbye, I must go now. Where Did My Program Fail? SPARCompiler Pascal can trace why a program failed; its traceback utility finds the routine that triggers the error. Using Pascal Traceback Pascal traceback installs signal handlers on selected signals and dumps a backtrace when those signals are caught.
2 Using a Sample Program with Segmentation Violation A segmentation violation occurs when your program tries to reference memory outside your address space. The operating system detects this action and generates an error message. Following is an example program, SegViol.
2 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.
2 Try compiling SegViol.p with –g: hostname% pc -g 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(), line 12 in “SegViol.
3 The Pascal Compiler The name of the Pascal compiler is pc. If you give pc a file name as an argument, and the file name ends with .p or .pas, pc compiles the file and leaves the result in an executable file, called a.out by default.
3 To identify the version number given an executable or object file created by the Pascal compiler, use the following command. hostname% mcs -p a.out | grep Pascal SC4.0 18 Mar 1995 Pascal 4.0 Compile and Link Sequence You can compile the file any.p with the following command-line: hostname% pc any.p This command actually invokes the compiler driver, which calls several programs or passes of the program, each of which processes the program. The output of each pass is the input to the next one.
3 Figure 3-1 shows the sequence of events when you invoke pc. Compiler pc Symbol conflict checking pc3 Source and include files Compiler preprocessor cpp or cppas Compiler frontend pc0 Optimize with -O[level] option Code generator cg Link editor ld Executable a.out Optimizer iropt Libraries Figure 3-1 Organization of Pascal Compilation Language Preprocessor The cpp(1) program is the C language preprocessor.
3 program showinclude; #include "file.i" begin ... end. See the man page for cpp(1) for information on its directives and other features. Appendix A, “Pascal Preprocessor,” describes cppas. File Name Extensions Accepted By pc Pascal source files generally use the extension .p. The compiler recognizes other file name extensions. Table 3-1 lists the most important extensions. The table notes that pc can produce assembler source files as well as unlinked object files.
3 Option-Passing on the Command-Line To pass an option on the command-line, use a dash (-) followed by the option name. In some cases, you must supply additional information, such as a file name. For example, this command activates the listing option -l, which is off by default: hostname% pc -l rmc.p The following command causes the generated object file to be named rmc instead of the default, a.out. hostname% pc -o rmc rmc.
3 Table 3-2 Options That Can Be Passed in Program Text (Continued) Option Description P Uses partial evaluation of boolean expressions. t Uses runtime checks (same as C, but different from the command-line t1). u Trims to 72-character line (not usable on command-line). w Prints warning diagnostics. 1.
3 When the compiler encounters an option followed by... This is what happens... + The current value is pushed onto the stack, and the current value becomes ON. - The current value is pushed onto the stack, and the current value becomes OFF. * The last value is popped off the stack and becomes the current value. If no values have been pushed onto the stack, the effect of * is undefined. Figure 3-2 illustrates how options are passed in program text.
3 –a The –a option is the old style of basic block profiling for tcov. See -xprofile=tcov for information on the new style of profiling and the tcov(1) man page for more details. Also see the manual, Profiling Tools. The –a option inserts code to count how many times each basic block is executed. It also calls a runtime recording mechanism that creates a .d file for every .p file at normal termination. The .d file accumulates execution data for the corresponding source file.
3 The –b option on the command-line turns on block-buffering with a block size of 1,024. You cannot turn off buffering from the command-line. If you give the –b option in a comment in the program, you can turn off buffering or turn on block buffering. The valid values are: {$b0} No buffering {$b1} Line buffering {$b2} Block buffering. The block size is 1,024. Any number greater than 2 (for example, {$b5}) is treated as {$b2}. You can only use this option in the main program.
3 –c The –c option instructs the compiler not to call the linker, ld(1). The Pascal compiler, pc, leaves a .o or object file for each source file. Without –c, pc calls the linker when it finishes compilation, and produces an executable file, called a.out by default. -calign The -calign option instructs the compiler to allocate storage in records the same way as the C compiler allocates structures. See the Pascal 4.0 Reference Manual for details of how data is aligned with and without -calign.
3 The –cond option instructs pc to compile the lines in your program that begin with the %debug compiler directive. If you compile your program without –cond, pc treats lines with the %debug directive as comments. –xl runs your program through the preprocessor cppas, which handles the Apollo DOMAIN®-style Pascal compiler directives, such as %debug. See Appendix A, “Pascal Preprocessor,” for a complete description of conditional variables, cppas, and compiler directives.
3 –dalign The –dalign option instructs the compiler to generate double load and store instructions wherever possible for faster execution. All double-typed data become double-aligned, so do not use this option when correct alignment is not ensured. -dn (Solaris 2.x only) The -dn option specifies static linking in the link editor. -dryrun The –dryrun option instructs the compiler to show, but not execute, the commands constructed by the compilation driver.
3 Do not use this option for programs that depend on IEEE standard exception handling; you can get different numerical results, premature program termination, or unexpected SIGFPE signals. Note – The criteria for the -fast option vary with the compilers from SunSoft: C, C++, FORTRAN 77, Fortran 90, and Pascal. See the appropriate documentation for the specifics. -fnonstd The -fnonstd option causes nonstandard initialization of floating-point arithmetic hardware.
3 The default is -fround=nearest. The meanings are the same as those for the ieee_flags subroutine. If you compile one routine with -fround=r, compile all routines of the program with the same –fround=r option; otherwise, unexpected results may occur. –ftrap=t (Solaris 2.x only) The -ftrap=t option sets the IEEE 754 trapping mode in effect at startup. t is a comma-separated list of one or more of the following: %all, %none, common, [no%]invalid, [no%]overflow, [no%]underflow, [no%]division, [no%]inexact.
3 –g The –g option instructs pc to produce additional symbol table information for dbx and debugger. With -g, the incremental linker, ild, is called, instead of ld. You can compile using both the -g and -O options. However, there are some side effects: • • The next and step commands do not work, but the cont command does. • If you have makefiles that check for a warning message that -g overrides -O, you must revise those make files.
3 Every executable file has a list of needed shared library files. When the runtime linker links the library into an executable file, the linker copies the intrinsic name from the library into that list of needed shared library files. If there is no intrinsic name of a shared library, then the linker copies the path of the shared library file instead. –help or -flags The –help or -flags option lists and summarizes all available options.
3 –L The –L option maps all keywords and identifiers to lowercase. In Pascal, uppercase and lowercase are not interchangeable in identifiers and keywords. In standard Pascal, the case is insignificant outside of character strings and character constants. The –L option is most useful for transporting programs from other systems. See also the –s option. –l The –l option produces a listing of the program. For example: hostname% pc -l random.p Pascal PC -- Version SC4.0 09 Jan 1995 Pascal 4.
3 -libmieee Forces IEEE 754 style return values for math routines in exceptional cases. In such cases, no exception message is printed, and errno is not set. –libmil The –libmil option instructs the compiler to select the best inline templates for the floating-point option and operating system release available on this system. –llib The –llib option links ld(1) with the object library, lib. Do not use the -lucb option because Pascal is not compatible with the object library, libucb.
3 –native The –native option causes pc to generate code for the best floating-point hardware available on the machine you are compiling on. The -fast macro includes -native in its expansion. (Solaris 2.x only) This option is a synonym for -xtarget=native. -nocx (Solaris 1.x only) The -nocx option makes the output executable file about 128K bytes smaller by not linking with the -lcx option. However, the runtime performance and accuracy of binary-decimal base conversion is somewhat compromised.
3 -notrace The -notrace option disables runtime traceback. It is only effective when compiling the main program. –O[level] The –O option instructs the compiler to run the compiled program through the object code optimizer. The –O option also calls the –P option, which ensures boolean expressions are only evaluated as much as needed to determine the result. This process causes an increase in compile time in exchange for a decrease in compiled code size and execution time.
3 –O3, -xO3 Same as -O2, but optimizes the uses and definitions of external variables. Level -O3 does not trace the effects of pointer assignments. Do not use Level -O3 when compiling device drivers or programs that modify external variables from within signal handlers. –O4, -xO3 Same as -O3, but traces the effects of pointer assignments and gathers alias information. Do not use Level -O4 when compiling device drivers or programs that modify external variables from within signal handlers.
3 This command causes the optimizer to try to recover if it reaches 16 megabytes of data space. This limit cannot be greater than the machine’s total available swap space, and in practice, should be small enough to permit normal use of the machine while a large compilation is in progress. For example, on a machine with 32 megabytes of swap space, the command limit datasize 16M ensures that a single compilation never consumes more than half of the machine’s swap space.
3 –p and –pg The –p and –pg options instruct the compiler to produce code that counts the number of times each routine is called. The profiling is based on a periodic sample taken by the system, rather than by line counters. Using the -p Option To generate an execution profile using the –p option: 1. Compile with the –p option. 2. Run a.out, which produces a mon.out executable file. 3. Type prof a.out. The program prints a profile.
3 –Qoption The –Qoption passes an option to the program. The option value must be appropriate to that program and can begin with a plus or minus sign. The program value can be either as(1) (Solaris 1.x only), fbe(1) (Solaris 2.x only), cpp(1), cppas, inline(1), iropt, ld(1), pc0, or pc3. For example, the following command passes the option -R to cpp and allows recursive macros: hostname% pc -Qoption cpp -R myprog.
3 -R (Solaris 1.x only) The –R option instructs pc to call the assembler, as(1). This option merges the data segment of the resulting program with the text segment. See also -xMerge (Solaris 2.x only). -R path[:dir] (Solaris 2.x only) The -Rpath[:dir] option passes a colon-separated list of directories that specify the library search path used by the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker.
3 The compiler issues warnings at the end of the procedure where the record variables are defined, that is, when some of the fields are definitely not set. However, no warnings are issued if fields are used in the source before they are initialized, as the control flow may be different. In some cases, it is not possible to determine at compile time whether the fields have actually been initialized.
3 Examples: The Pascal main program, r.p (record and array of records) program p; procedure qq; type compl = record re, im: integer end; arc = array[1..2] of compl; var z: compl; a: arc; begin writeln(z.im); writeln(a[1].re); end; begin end. 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.
3 The commands to compile rr.p and the -Rw warnings that are issued hostname% pc -Rw rr.p Mon Feb 20 14:59:04 1995 pas/rr.p: In procedure qq: w 18280 field r1.b is used but never w 18280 field r1.a is used but never w 18280 field r2.b is used but never w 18280 field r2.a is used but never set set set 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.
3 The Pascal main program, with.p (with statement) program p; type C = record re, im: integer end; AC = array[1..2] of C; RC = record C1, C2: C end; PRC = ^RC; procedure qq; var c: C; ac: AC; rc: RC; prc: PRC; begin ac[1]:= c; with ac[1] do begin re:= 1; 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.
3 –S The –S option compiles the program and outputs the assembly language in the file, sourcefile.s. For example, the following command places the assembly language translation of rmc.p in the file rmc.s. No executable file is created. hostname% pc –S rmc.p –s[level] The –s option instructs the compiler to accept standard Pascal only. Pascal has two levels of compliance with standard Pascal: Level 0 and Level 1. The only difference between the two is that Level 1 also allows conformant arrays.
3 -tc The -tc option instructs the compiler to generate pc3 stab information that allows cross-module type checking. This option can be used for two purposes: • To check for any name conflicts that your program may have with the standard libraries with which it is to be linked, such as libc. The linker allows name conflicts, which may cause erroneous runtime behavior in your program.
3 –time The –time option instructs the compiler to report execution performance statistics for the various compilation passes. Here is some sample output; some spaces have been removed so the output would fit on the page. hostname% pc -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 OUT:3b. pf IN:25p OUt:184p. pc0:time U:0.0s+S:0.3s=0.4s REAL:3.2s 13%. core T:0k D:4k. io IN:4b OUT:4b. pf IN:70pOUT:131p. cg: time U:0.0s+S:0.1s=0.2s REAL:2.0s 12%. core T:0k D:1k.
3 –U name The –U option removes any initial definition of the cpp(1) symbol name. See cpp(1) for more information. You cannot use this option with the -xl option. –V The –V option prints the version number of each compilation pass.
3 a must be one of: generic, v7, v8, v8a, v8plus, v8plusa. Although this option can be used alone, it is part of the expansion of the xtarget option; its primary use is to override a value supplied by the xtarget option. This option limits the instructions generated to those of the specified architecture, and allows the specified set of instructions. It does not guarantee an instruction is used; however, under optimization, it is usually used.
3 v7, v8, and v8a are all binary compatible. v8plus and v8plusa are binary compatible with each other and forward, but not backward. For any particular choice, the generated executable can run much more slowly on earlier architectures (to the left in the above list). Table 3-3 The -xarch Values Value Meaning generic Get good performance on most SPARCs, and major degradation on none. This is the default.
3 Table 3-3 The -xarch Values (Continued) Value Meaning v8 Limit the instruction set to V8 architecture. This option uses the best instruction set for good performance on the V8 architecture, but without quad-precision floating-point instructions. Example: SPARCstation 10 v8plus Limit the instruction set to the V8plus version of the V9 architecture.
3 -xcache=c (Solaris 2.x only) The -xcache=c option defines the cache properties for use by the optimizer.
3 Example: -xcache=16/32/4:1024/32/1 specifies the following: 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 -xchip=c (Solaris 2.x only) The -xchip=c option specifies the target processor for use by the optimizer.
3 Table 3-5 The -xchip Values (Continued) Value Meaning micro2 Use timing properties of the MicroSPARC II chip. hyper Use timing properties of the HyperSPARC™ chip. hyper2 Use timing properties of the HyperSPARC II chip. powerup Use timing properties of the Weitek® PowerUp™ chip. ultra Use timing properties of the UltraSPARC chip. -xcg89 Same as -cg89. -xcg92 Same as -cg92. –xF (Solaris 2.
3 -xildoff (Solaris 2.x only) Turns off the incremental linker and forces the use of ld. This option is the default if you do not use the -g option, or you do not use the -G option, or any source files are present on the command line. Override this default by using the -xildon option. -xildon (Solaris 2.x only) Turns on the incremental linker and forces the use of ild in incremental mode.
3 -xlibmopt Uses a math routine library optimized for performance. The results may be slightly different than those produced by the normal math library. This option is implied by the -fast option. –xlicinfo The -xlicinfo option returns information about the licensing system. In particular, it returns the name of the license server and the IDs of users who have licenses checked out. When you give this option, the compiler is not invoked and a license is not checked out. –xMerge (Solaris 2.
3 Generates the highest level of optimization. Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Optimization at this level is more likely to improve performance if it is done with profile feedback. See -xprofile=p.
3 This option causes execution frequency data to be collected and saved during execution, then the data can be used in subsequent runs to improve performance. Table 3-6 The -xprofile Values Value Meaning collect Collect and save execution frequency for later use by the optimizer. The compiler inserts code to measure the execution frequency at a low level. During execution, the measured frequency data is written into .prof files that correspond to each of the source files.
3 -xregs=r (Solaris 2.x only) The -xregs=r option specifies the usage of registers for the generated code. r is a comma-separated list that consists of one or more of the following: [no%]appl, [no%]float. Example: -xregs=appl,no%float Table 3-7 The -xregs Values Value Meaning appl Allow using the registers g2, g3, and g4. In the SPARC ABI, these registers are described as application registers. Using these registers can increase performance because fewer load and store instructions are needed.
3 –xs (Solaris 2.x only) The -xs option disables Auto-Read for dbx in case you cannot keep the .o files around. This option passes the -s option to the assembler and the linker. • No Auto-Read—This is the older way of loading symbol tables. • The compiler instructs the linker to place all symbol tables for dbx in the executable file. • The linker links more slowly and dbx initializes more slowly.
3 -xspace (Solaris 2.x only) The -xspace option does no optimizations that increase the code size. Example: Do not unroll loops. -xtarget=t (Solaris 2.x only) The -xtarget=t option specifies the target system for the instruction set and optimization. t must be one of: native, generic, system-name. The -xtarget option permits a quick and easy specification of the -xarch, -xchip, and -xcache combinations that occur on real systems. The only meaning of -xtarget is in its expansion.
3 very important. This is especially true when running on the newer SPARC processors. However, for most programs and older SPARC processors, the performance gain is negligible and a generic specification is sufficient. Each specific value for -xtarget expands into a specific set of values for the xarch, -xchip, and -xcache options. See Table 3-9 for the values.
3 64 -xtarget -xarch -xchip -xcache sun4/670 v7 old 64/32/1 sun4/690 v7 old 64/32/1 sselc v7 old 64/32/1 ssipc v7 old 64/16/1 ssipx v7 old 64/32/1 sslc v8a micro 2/16/1 sslt v7 old 64/32/1 sslx v8a micro 2/16/1 sslx2 v8a micro2 8/64/1 ssslc v7 old 64/16/1 ss1 v7 old 64/16/1 ss1plus v7 old 64/16/1 ss2 v7 old 64/32/1 ss2p v7 powerup 64/31/1 ss4 v8a micro2 8/64/1 ss5 v8a micro2 8/64/1 ssvyger v8a micro2 8/64/1 ss10 v8 super 16/32/4 s
3 -xtarget -xarch -xchip -xcache ss10/51 v8 super 16/32/4:1024/32/1 ss10/61 v8 super 16/32/4:1024/32/1 ss10/71 v8 super2 16/32/4:1024/32/1 ss10/402 v8 super 16/32/4 ss10/412 v8 super 16/32/4:1024/32/1 ss10/512 v8 super 16/32/4:1024/32/1 ss10/514 v8 super 16/32/4:1024/32/1 ss10/612 v8 super 16/32/4:1024/32/1 ss10/712 v8 super2 16/32/4:1024/32/1 ss20/hs11 v8 hyper 256/64/1 ss20/hs12 v8 hyper 256/64/1 ss20/hs14 v8 hyper 256/64/1 ss20/hs21 v8 hyper 256/64/1
3 -xtarget -xarch -xchip -xcache ss600/140 v7 old 64/32/1 ss600/412 v8 super 16/32/4:1024/32/1 ss600/ v8 super 16/32/4:1024/32/1 ss600/ v8 super 16/32/4:1024/32/1 ss600/ v8 super 16/32/4:1024/32/1 ss1000 v8 super 16/32/4:1024/32/1 sc2000 v8 super 16/32/4:1024/64/1 cs6400 v8 super 16/32/4:2048/64/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
Program Construction and Management 4 This chapter is an introduction to the methods generally used to construct and manage programs using Pascal. It describes units and libraries in two separate sections: Units page 67 Libraries page 74 Units For many reasons, it is often inconvenient to store a program in a single file, as in the case of a very large program. You can break up a program in several ways. Perhaps the simplest way is to use an include file.
4 The actual includefile looks like this: begin writeln ('Hello, world.') end. In this example, the include file contains the entire program. In reality, an include file probably contains a set of variable or procedure declarations. include files are often used when a set of declarations needs to be shared among a number of programs. However, suppose your program is very large and takes a long time to compile.
4 The body of the procedure say_hello is not defined in this program unit, but the program unit does contain a declaration of the interface to the procedure. The keyword extern declares that say_hello is declared in a module unit.1 • Module unit—This unit can begin with an optional module header, followed by a set of compilable declarations and definitions. Modules that call externally defined routines must have declarations for those routines.
4 You can also separate the compilation and linking or loading steps, as follows: hostname% pc program_unit.p -c hostname% pc module_unit.p -c hostname% pc program_unit.o module_unit.o In this case, you call pc on each unit with the “compile only” option (-c), which produces an object file with the extension .o. When you use this option, the compiler driver does not call the linker, ld.
4 In a real program, header.h would probably contain many declarations and would be included in several modules. Aside from routine declarations, header files often contain constant, type, and variable declarations. Sharing Variables Between Units Variables that are global across a unit (that is, not declared locally in a routine) can be public or private. A public variable can be shared by any unit that is linked to the unit that declares the variable. A private variable cannot be shared.
4 Here is a program unit that declares a variable: program program_unit3 (output); var x : integer; procedure say_hello; external; begin for x := 1 to 5 do say_hello end. Here is a module unit that declares a variable with the same name: module module_unit3; var x : integer; procedure say_hello; begin writeln ('Hello, world for the', x, ' time.') end; 72 Pascal 4.
4 By default, both definitions of variable x are public. Thus, when you compile and link the program and module units, references to x refer to the same variable, as follows: 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 the 2 time. Hello, world for the 3 time. Hello, world for the 4 time. Hello, world for the 5 time.
4 Libraries You can use a module unit as a library of useful functions. The simplest way to do so is to create a source file containing the definitions of your library routines and then compile it using the -c option. You can then link the resulting .o file to any number of files. For convenience, you probably should create a header file containing the routine declarations for the library.
5 Separate Compilation This chapter describes how to compile Pascal programs in separate units. Chapter 4, “Program Construction and Management,” gives an introduction to the concepts in this chapter. Following are the sections: Working with Units page 75 Sharing Variables and Routines Across Multiple Units page 76 Sharing Declarations in Multiple Units page 87 In separate compilation, a program is divided into several units that can be separately compiled into object (.o) files.
5 Using Program Units The program unit is the source program with the program header. It has the following syntax: ::= Each program you write can have only one program unit. The program body is the first code that Pascal executes. Using Module Units A module unit is a source program that does not have a program header.
5 Compiling without the -xl Option There are three ways of sharing variables and routines across units when you compile your program without the –xl option. Sharing Public Variables If you declare a variable in two or more separate units and the variable is public in both places, that variable is shared between units. Variables are public by default, unless you compile with the -xl option, in which case variables are private by default.
5 The commands to compile and execute shrvar_prog.p and shrvar_mod.p hostname% pc shrvar_prog.p shrvar_mod.p shrvar_prog.p: shrvar_mod.p: Linking: hostname% a.out From MAIN, before PROC: 1 From PROC : 1 From MAIN, after PROC : 2 Using extern Option to Share Routines If a program or module calls a procedure not defined in that unit, you must declare it with either the extern or external routine option. For instance, in the previous example, the procedure proc is defined in shrvar_mod.
5 The program unit, inc_prog.p, which includes the file include.h program inc_prog; #include "include.h" begin { program body} global := 1; writeln('From MAIN, before PROC: ', global); proc; writeln('From MAIN, after PROC: ', global) end. { inc_prog } 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 + 1 end; { proc } The include file, include.
5 Using the -xl Option When you use the –xl option, variables and top-level procedures and functions declared in the program unit default to private. Look at the difference when you compile and execute shrvar_prog.p and shrvar_mod.p with –xl. See the source code in “Sharing Public Variables” on page 77. The commands to compile and execute shrvar_prog.p and shrvar_mod.p with the –xl option hostname% pc -xl shrvar_prog.p shrvar_mod.p shrvar_prog.p: shrvar_mod.p: Linking: hostname% a.
5 The program unit, pubvar_prog.p, which declares global as public program pubvar_prog; public var global: integer; procedure proc; external; begin global := 1; writeln('From MAIN, before PROC: ', global); proc; writeln('From MAIN, after PROC: ', global) end. { pubvar_prog } The module unit, pubvar_mod.
5 Using the define Variable Attribute This example makes global public using the define attribute of the variable declaration. The program unit, defvar_prog.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.
5 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 Using the define Declaration This example defines global in the module defvar_mod2 using the define declaration. The advantage of using the define declaration over the define variable attribute is that the define declaration can be easily converted to use include files.
5 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 + 1; end; { proc } The commands to compile and execute defvar_prog.p and defvar_mod2.p : ',global); hostname% pc -xl defvar_prog.p defvar_mod2.p defvar_prog.p: defvar_mod2.p: Linking: hostname% a.
5 The program unit, inc_prog2.p program inc_prog2; %include "include2.h"; procedure proc; 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 + 1; end; { proc } The include file, include2.
5 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 Using extern In the previous example, the extern definition for variables is put into an include file and then shared. You can do the same for the extern procedure definition.
5 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_mod.p hostname% pc -xl ext_prog.p ext_mod.p ext_prog.p: ext_mod.p: Linking: hostname% a.
5 For routines declared extern fortran or external fortran, the changes in the calling sequence are as follows: • For value parameters, the compiler creates a copy of the actual argument value in the caller’s environment and passes a pointer to the temporary variable on the stack. Thus, you need not create (otherwise useless) temporary variables. • The compiler appends an underscore to the name of the external procedure to conform to a naming convention of the f77(1) compiler.
6 The C–Pascal Interface This chapter describes how to mix C and Pascal modules in the same program.
6 The -c option produces an unlinked object file. The -calign option causes pc to use C-like data formats for aggregate objects. When you compile a Pascal main routine that calls C, you don’t have to use any special options, but the -calign option is again useful. The C object library, libc, is automatically brought in for every Pascal compilation. For example: hostname% cc -c my_c.c hostname% pc -calign my_c.o my_pascal.
6 Table 6-1 C and Pascal Size and Alignment of Compatible Types (Continued) Pascal Type C Type Size (bytes) array array - Same as element type variant record struct/union - - fields in packed record bit field - - Table 6-2 Alignment (bytes) C and Pascal Size and Alignment of Compatible Types with –xl Pascal Type C Type Size (bytes) Alignment (bytes) real float 4 4 integer short int 2 2 Precautions with Compatible Types This section describes the precautions you should take wh
6 Array Indexes Pascal array indexes can start at any integer; C array indexes always start at zero. Aggregate Types Aggregate types include arrays, varying arrays, sets, strings, alphas, records, and variant records. Pascal aggregate types may require alignment and layout adjustment to match C unions, structures, and arrays. Pascal aggregate types can be any of the following: arrays, varying arrays, sets, strings, alphas, records, or variant records.
6 Pascal Set Types In Pascal, a set type is implemented as a bit vector, which is similar to a C short-word array, where each short-word contains two bytes. Thus, sets are bit-vectors, and they are allocated in multiples of 16 bits. To find out the size of a set, enter the following code: ceiling( ord( highest_element ) / 16 ) Direct access to individual elements of a set is highly machine-dependent and should be avoided.
6 The C main program, SampMain.c. Note the procedure definition and call. #include 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 Variable Parameters Pascal passes all variable parameters by reference, which C can do, too. 94 Pascal 4.
6 Simple Types without –xl Without -xl, simple types match, as in the following example: The Pascal procedure, SimVar.p procedure SimVar( var t, f: boolean; 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
6 The commands to compile and execute SimVar.p and SimVarMain.c hostname% hostname% hostname% 00000001 pc -c SimVar.p cc SimVar.o SimVarMain.c a.out 00000000 z 9 9 9.9 9.9 Simple Types with –xl With the -xl option, the Pascal real must be paired with a C float, and the Pascal integer must be paired with a C short int. Strings of Characters The C counterpart to the Pascal alfa and string types are arrays; C passes all arrays by reference.
6 The C main program, StrVarMain.c #include #include struct TVarLenStr { int nbytes; char a[25]; }; extern void StrVar(char *, char *, struct TVarLenStr *); int main(void) { struct TVarLenStr vls; char s10[10], s80[80], s25[25]; vls.nbytes = 0; StrVar(s10, s80, &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.
6 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 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); } The commands to compile and execute FixVec.p and FixVecMain.c hostname% pc -c -calign FixVec.
6 The Pascal procedure, DaysOfWeek.p type TDay= array [0..8] of char; TWeek = array [0..6] of day; TYear = array [0..51] of week; procedure DaysOfWeek(var Y: TYear); begin v[1][1] := 'Sunday'; end; The C main program, DaysOfWeekMain.c #include extern void 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.
6 The univ Arrays You can pass any size array to a Pascal procedure expecting a univ array, although there is no special gain in doing so, because there is no type or size checking for separate compilations. However, if you want to use an existing Pascal procedure that has a univ array, you can do so. All univ arrays that are in, out, in out, or var parameters pass by reference. The Pascal procedure, UniVec.p, which defines a 10element array type TVec = array [0..
6 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 Conformant Arrays For single-dimension conformant arrays, pass upper and lower bounds, placed after the declared parameter list. If the array is multidimensional, pass element widths as well, one element width for each dimension, except the last one. See this example: function ip(var x: array [lb..
6 Examples of single-dimension, multidimension, and array-of-character conformant arrays follow. Conformant arrays are included here only because they are a relatively standard feature; there are usually more efficient and simpler ways to do the same thing. Example 1: Single-Dimension Array 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
6 Example 2: Multi-Dimension Array The Pascal procedure, RealCA.p. Pascal passes low bound, high bound, and element width. procedure RealCA(var A: array [r1..r2: integer] of array [c1..c2: integer] of real); var col, row: integer; begin for row := r1 to r2 do for col := c1 to c2 do if row = col then A[row, col] := 1.0 else A[row, col] := 0.0 end; { RealCA } The C main program, RealCAMain.c. Array M has 2 rows of 3 columns each. c1 and c2 are the first and last columns.
6 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 1.0 0.0 0.0 If wc is the width of the smallest element, as determined by sizeof(), then the width of the next largest element is the number of those smaller elements in the next larger element multiplied by wc.
6 The commands to compile and execute ChrCAVar.p and ChrCAVarMain.c hostname% hostname% hostname% This is a pc -c -calign ChrCAVar.p cc ChrCAVar.o ChrCAVarMain.c -lpc a.out string Records and Structures In most cases, a Pascal record describes the same objects as its C structure equivalent, provided that the components have compatible types and are declared in the same order. The compatibility of the types depends mostly on size and alignment.
6 The C main program, StruChrMain.c #include #include 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 hostname% a.
6 Consider this example: The Pascal routine, 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' + chr(0); W[1].TWeather := 'Sunny' + chr(0); WeatherSize := 5; end; { StruChr } The C main program, DayWeatherMain.c #include #include
6 When you compile the Pascal routine without using the -calign option, the program does not work correctly. 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.
6 The C main program, VarRecMain.c #include struct vlr { char tag; union { struct { char ch1, ch2; }a_var; struct { char flag; }b_var; struct { int ALIGN; }c_var; }var_part; }; extern void VarRec(struct vlr *); int main(void) { struct vlr *x; x = (struct vlr *)malloc(sizeof(struct vlr)); x->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.
6 Pascal Set Type In Pascal, a set type is implemented as a bit vector, which is similar to a C short-word array. Direct access to individual elements of a set is highly machine-dependent and should be avoided. In Pascal, bits are numbered within a byte from the most significant to least, as shown in Table 6-3.
6 Pascal intset Type The Pascal intset type is predefined as set of [0..127]. A variable of this type takes 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 C main program, IntSetVarMain.c #include
6 Value Parameters There are three types of value parameters in Pascal. Simple Types without –xl Without –xl, simple types match, as in the following example: The Pascal procedure, SimVal. p. t, f, c, i, r, and s are value parameters.
6 The C main program, SimValMain.c #include extern void SimVal( char, char, char, short, int, float, double, int *); int main(void) { char char short int float double int t = 1, f = 0; c = 'z'; si = 9; i = 9; sr = 9.9; r = 9.9; args; SimVal(t, f, c, si, i, sr, r, &args); printf(" args = %06o \n", args); The commands to compile and execute SimVal.p and SimValMain.c hostname% pc -c SimVal.p hostname% cc SimVal.o SimValMain.c -lpc hostname% a.
6 Arrays Since C cannot pass arrays by value, it cannot pass strings of characters, fixed arrays, or univ arrays by value. Conformant Arrays Pascal passes all value parameters on the stack or in registers, except for value conformant array parameters, which are handled by creating a copy in the caller environment and passing a pointer to the copy. In addition, the bounds of the array must be passed (see “Conformant Arrays” on page 101).
6 The commands to compile and execute ChrCAVal.p and ChrCAValMain.c with -calign hostname% hostname% hostname% This is a pc -c -calign ChrCAVal.p cc ChrCAVal.o ChrCAValMain.c -lpc a.out string Function Return Values Function return values match types the same as with parameters, and they pass in much the same way. Simple Types The simple types pass in a straightforward way, as follows: The Pascal function, RetReal.p function RetReal(x: real): real; begin RetReal := x + 1.
6 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 Input and Output If your C main program calls a Pascal procedure that does I/O, then include the following code in the C main program before you call the Pascal procedure: __PC0__PCSTART(); Also, in the C main program just before exit, add the following line: __PC0__PCEXIT(); See this example: The Pascal procedure, IO.
6 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! Procedure Calls: Pascal–C This section parallels the section, “Procedure Calls: C–Pascal” on page 93. Earlier comments and restrictions also apply here. Variable Parameters Pascal passes all variable parameters by reference, which C can do, too.
6 The Pascal main program, SimRefMain.p program SimRefMain(output); var 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.
6 The C function, StrVar.c #include struct TVarLenStr { int nbytes; char a[26]; }; void StrVar(char *s10, char *s80, struct TVarLenStr *vls) { static char ax[11] = "abcdefghij"; static char sx[81] = "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.
6 The commands 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 Avoid constructs that rely on strings being in static variable storage. For example, you could use mktemp(3) in Pascal as follows: Incorrect use of string in static variable storage tmp := mktemp('/tmp/eph.xxxxxx') This use is incorrect, since mktemp()modifies its argument.
6 Fixed Arrays For a fixed-array parameter, pass the same type and size, as in this example: The C function, FixVec.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.
6 The univ Arrays The univ arrays that are in, out, in out, or var parameters pass by reference. Here is an example: The C function, UniVec.c void UniVec(int V[3], int Last, int *Sum) { int i; *Sum = 0; for (i = 0; i <= Last; 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..
6 The -calign option is not needed for this example, but may be necessary if the array parameter is an array of aggregates. Conformant Arrays For single-dimension conformant arrays, pass upper and lower bounds placed after the declared parameter list. If the array is multidimensional, pass element widths as well, one element width for each dimension, except the last one. Chapter 8, “The FORTRAN–Pascal Interface,” has an example of multidimensional conformant array passing.
6 The commands to compile and execute IntCA.c and IntCAMain.p hostname% cc -c IntCA.c hostname% pc -calign IntCA.o IntCAMain.p hostname% a.out 4 4 4 The -calign option is not needed for this example, but may be necessary if the array parameter is an array of aggregates. Records and Structures In most cases, a Pascal record describes the same objects as its C structure equivalent, provided that the components have compatible types and are declared in the same order.
6 The Pascal main program, StruChrMain.p program 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.
6 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'; } 126 Pascal 4.
6 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 VarRecMain.p hostname% cc -c VarRec.c hostname% pc -calign VarRec.o VarRecMain.p hostname% a.
6 See this example: The C function, NonPas.c. In the function for_C, s is a pointer (declared var in the procedure declaration), and len is not a pointer (not declared var in the procedure declaration). In the function for_nonpascal, s is still a pointer (though not declared var in the procedure declaration), and len is now a pointer (though not declared var). #include The Pascal main program, NonPasMain.
6 Value Parameters In general, Pascal passes value parameters in registers or on the stack, widening to a full word if necessary. Simple Types With value parameters, simple types match, as in the following example: 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) if (!f) if (c == 'z') if (si == 9) if (i == 9) if (sr ==(float)9.9) if (r == 9.
6 The Pascal main program, SimValMain.p program SimVal(output); var t: boolean f: boolean c: char si: integer16 i: integer sr: shortreal r: double args: integer; := := := := := := := true; false; 'z'; 9; 9; 9.9; 9.9; 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.
6 The C function, RetReal.c double RetReal(double *x) { return(*x + 1.0); } The Pascal main program, RetRealMain.p program RetRealMain; var r, s: real; function RetReal(var x: real): real; 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.
6 The Pascal main program, ProcParMain.p, which calls the C procedure, proc_c, passing it the address of the 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.
6 functions can be passed to other languages as arguments, the static links for all procedure or function arguments are placed after the end of the conformant array bounds pairs, if any. Routines in other languages can be passed to Pascal; a dummy argument must be passed in the position normally occupied by the passed routine’s static link. If the passed routine is not a Pascal routine, the argument is used only as a placeholder.
6 The commands to compile and execute GloVar.p and GloVarMain.c without –xl. With -xl, the Pascal integer must be paired with a C short int and declared public since the default visibility is private. hostname% pc -c GloVar.p hostname% cc GloVar.o GloVarMain.c hostname% a.out 2001 File-Passing Between Pascal and C You can pass a file pointer from Pascal to C, then have C do the I/O, as in: The C procedure, UseFilePtr.c #include
6 The commands 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.
6 136 Pascal 4.
7 The C++–Pascal Interface This chapter describes how to mix C++ and Pascal modules in the same program.
7 Compatibility of Types for C++ and Pascal Table 6-1 and Table 6-2 on page 90 list the default sizes and alignments of compatible types for C and Pascal. They apply to C++ as well. C++ Name Encoding To implement function overloading and type-safe linkage, the C++ compiler normally appends type information to the function names. To prevent the C++ compiler from doing so, and to allow Pascal to call a C++ function, declare the C++ function with the extern "C" language construct.
7 The C++ main program, SampMain.cc #include 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 Arguments Passed by Reference C++ arguments can be passed by reference. This section describes how they work with Pascal.
7 Simple Types without the -xl Option Without the -xl option, simple types match, as in the following example: The Pascal procedure, SampRef, in the file, Samp.p procedure var t, var c: var i: var s: var r: var d: ); begin t := f := c := i := s := r := d := end; 140 SamRef ( f: boolean; char; integer; integer16; shortreal; real true; false; 'z'; 9; 9; 9.9; 9.9; Pascal 4.
7 The C++ main program, SamRefMain.cc #include extern "C" char char char int short float double void SamRef ( &, &, &, &, &, &, &); 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.
7 Strings of Characters The C++ counterpart to the Pascal alfa and string types are arrays. The C++ counterpart to the Pascal varying type is a structure. Here is an example: The Pascal procedure, StrRef.p type TVarStr = varying [25] of char; procedure var a: var s: var v: ); StrRef ( alfa; string; TVarStr begin a := 'abcdefghi' + chr(0); s := 'abcdefghijklmnopqrstuvwxyz' + chr(0); v := 'varstr' + chr(0); end; 142 Pascal 4.
7 The C++ main program, StrRefMain.cc #include #include struct TVarLenStr { int NBytes; char a[25]; }; extern "C" void StrRef ( char *, char *, TVarLenStr &); int main(void) { struct TVarLenStr vls; char s10[10], s80[80], s25[25]; vls.NBytes = 0; StrRef (s10, s80, vls); strncpy (s25, vls.a, 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.
7 Fixed Arrays The Pascal procedure, FixVec.p type TVec = 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; The C++ main program, FixVedMain.cc #include 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 144 hostname% pc -c FixVec.
7 Although it does not apply to this example, arrays of aggregates in Pascal have, by default, a size that is a multiple of four bytes. When you use the -calign option to compile Pascal code, that difference from C++ is eliminated. The following example illustrates this point. The string 'Sunday' 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..
7 The commands to compile and execute DaysOfWeek.p and DaysOfWeekMain.cc without the -calign option hostname% pc -c DaysOfWeek.p hostname% CC DaysOfWeek.o DaysOfWeekMain.cc -lpc hostname% a.out Day = '' The commands to compile and execute DaysOfWeek.p and DaysOfWeekMain.cc with the -calign option hostname% pc -c -calign DaysOfWeek.p hostname% CC DaysOfWeek.o DaysOfWeekMain.cc -lpc hostname% a.
7 The C++ main program, StruChrMain.cc #include #include struct TVarLenStr { int NBytes; char a[25]; }; extern "C" void 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.
7 Consider this example: The Pascal procedure, 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; 148 Pascal 4.
7 The C++ main program, DayWeatherMain.cc #include #include 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].
7 When you compile the Pascal routine without the -calign option, the program does not work correctly. Compile with the -calign option. The program now works correctly. hostname% hostname% hostname% day = '' weather = pc -c DayWeather.p CC DayWeather.o DayWeatherMain.cc -lpc a.out ' Sun' hostname% pc -calign -c DayWeather.p hostname% CC DayWeather.o DayWeatherMain.cc -lpc hostname% a.out day = 'Sunday' weather = 'Sunny' Arguments Passed by Value C++ arguments can be passed by value.
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.
7 The C++ main program, SimValMain.cc #include 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.
7 Simple Types Simple types pass in a straightforward way, as in the following example: The Pascal function, RetReal.p function RetReal (r: real): real; begin RetReal := r + 1 end; The C++ main program, RetRealMain.cc #include 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.
7 Type shortreal The Pascal function, RetShortReal.p function RetShortReal (r: shortreal): shortreal; begin RetShortReal := r + 1.0 end; The C++ main program, RetShortRealMain.cc #include #include 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.
7 The C++ main program, IOMain.cc #include 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 ! Hello, C++ ! Procedure Calls: Pascal–C++ A Pascal main program can also call C++ functions.
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 char char int short &t, &f, &c, &i, &s, float &r, double &d) { t f c i s = = = = = 1; 0; 'z'; 9; 9; r = 9.9; d = 9.9; } 156 Pascal 4.
7 The Pascal main program, SimRefMain.p program SimRefMain (output); var t, f: boolean; c: char; i: integer; s: integer16; r: shortreal; d: real; procedure var t, var c: var i: var s: SimRef ( f: boolean; char; integer; 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.
7 Simple Types Simple types match with value parameters. See the following example: The C++ function, SimVal.cc 158 extern "C" void SimVal( char t, char f, char c, short si, int i, float sr, double r, int& Reply) { Reply = 0; if (t) if (! f) if (c == 'z') if (si == 9) if (i == 9) if (sr == (float)9.9) if (r == 9.9) } Pascal 4.
7 The Pascal main program, SimValMain.p program SimValMain(output); var 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.
7 The following example shows how to pass simple types: The C++ function, RetReal.cc extern "C" double RetReal (double &x) { return (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 160 hostname% CC -c RetReal.cc hostname% pc RetReal.o RetRealMain.
7 Global Variables in C++ and Pascal If the types are compatible, a global variable can be shared between C++ and Pascal. See this example: The Pascal procedure, GloVar.p var Year: integer; procedure GloVar; begin Year := 1995; end; The C++ main program, GloVarMain.cc #include 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.
7 Pascal File Pointers to C++ You can pass a file pointer from Pascal to C++, then have C++ do the I/O. See this example. The C++ procedure, UseFilePtr.cc #include extern "C" void UseFilePtr { fprintf (ptr, fprintf (ptr, fprintf (ptr, } The C++ main program, UseFilePtrMain.p (FILE* ptr) "[1] \n"); "[2] \n"); "[3] \n"); program UseFilePtrMain (output); var f: text; cfile: univ_ptr; procedure UseFilePtr (cf: univ_ptr); external C; begin rewrite (f, 'myfile.
8 The FORTRAN–Pascal Interface This chapter describes how to mix FORTRAN 77 and Pascal modules in the same program.
8 Specify –lpfc on the command-line before –lpc. For example: hostname% pc -c my_pascal.p hostname% f77 my_pascal.o my_fortran.f -lpfc -lpc Sampmain.f: MAIN: The -c option to pc produces an unlinked object file. When you compile a Pascal main routine that calls FORTRAN, you must use the compiler options –lpfc and –lF77. The –lF77 option links the FORTRAN object library, libf77. You must specify -lpfc on the command-line before -lF77. For example: hostname% f77 -c my_fortran.f hostname% pc my_fortran.
8 Table 8-1 Default Sizes and Alignments of Compatible Types (Pascal and FORTRAN) Pascal Type FORTRAN Type Size (Bytes) Alignment (Bytes) double double precision 8 8 longreal double precision 8 8 real double precision 8 8 single real 4 4 shortreal real 4 4 integer16 integer*2 2 2 integer32 integer*4 4 4 integer integer*4 4 4 -128..
8 Character Strings There are some precautions to take with character strings regarding the null byte, passing by value, and static storage: • Set the byte count to zero before calling Pascal with a null varying string, because that is what Pascal assumes about such strings. • Pass a structure consisting of a 4-byte integer and an array of characters from FORTRAN to a Pascal procedure, expecting a var parameter that is a variable-length string.
8 Pascal Set Types In Pascal, a set type is implemented as a bit vector, which is similar to a FORTRAN 16-bit word. Direct access to individual elements of a set is highly machine-dependent and should be avoided. Multidimensional Arrays Pascal multidimension arrays are incompatible with FORTRAN multidimension arrays. Since Pascal arrays use row-major indexing, and FORTRAN arrays use column-major indexing, an array passed in either direction appears to be transposed.
8 Procedure Calls: FORTRAN-Pascal Here are examples of how a FORTRAN main program calls a Pascal procedure. The Pascal procedure, Samp.p. Note the procedure definition. The procedure name in the procedure statement is in lowercase with a trailing underscore (_). This format is required to match the conventions of the FORTRAN compiler. var parameters are used to match FORTRAN defaults. procedure samp_(var i: integer; var r: real); The FORTRAN main program, Sampmain.f.
8 See the following example: The Pascal procedure, SimVar.p procedure simvar_(var t, f: boolean; var c: char; var i: integer; var r: real; var si: integer16; var sr: shortreal); begin t := true; f := false; c := 'z'; i := 9; r := 9.9; si := 9; sr := 9.9 end; { simvar_ } The FORTRAN main program, SimVarmain.f logical*1 character integer*4 double precision integer*2 real t, f c i d si sr call SimVar ( t, f, c, i, d, si, sr ) write(*, "(L2,L2,A2,I2,F4.1,I2,F4.
8 Simple Types with the –xl Option When you pass the -xl option, the Pascal data type real must be paired with a FORTRAN data type real; the Pascal data type integer must be paired with a FORTRAN data type, integer*2. Strings of Characters The FORTRAN counterpart to the Pascal alfa and string types is a character string, and the FORTRAN counterpart to the Pascal varying is a structure. By default, FORTRAN, passes all by reference: The Pascal procedure, StrVar.
8 The commands to compile and execute StrVar.p and StrVarmain.f hostname% pc -c StrVar.p hostname% f77 StrVar.o StrVarmain.f -lpfc -lpc StrVarmain.f: MAIN: hostname% a.out s10='abcdefghij' s80='abcdefghijklmnopqrtstuvwxyz s25='oyvay' Fixed Arrays For a fixed array parameter, pass the same type and size by reference, as shown in the following example: The Pascal procedure, FixVec.p type VecTyp = array [0..
8 The commands 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 univ Arrays You can pass any size array to a Pascal procedure expecting a univ array, but there is no advantage in doing so, since there is no type or size checking for separate compilations. However, if you want to use an existing Pascal procedure that has a univ array, you can do so.
8 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 Conformant Arrays For conformant arrays, with single-dimension array, pass upper and lower bounds, placed after the declared parameter list, as in: function ip(var x:array[lb..ub:integer] of real):real; ... double precision v1(10) double precision z z = ip ( v1, %VAL(0), %VAL(9) ) ...
8 Example 1: Single-Dimension Array The Pascal procedure, IntCA.p. Pascal passes the bounds by value. The FORTRAN main program, IntCAmain.f The commands to compile and execute IntCA.p and IntCAmain.f procedure intca_(var a: array [lb..ub: integer] of integer); begin a[1] := 1; a[2] := 2 end; { intca_ } 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 hostname% pc -c IntCA.p hostname% f77 IntCA.o IntCAmain.
8 The FORTRAN main program, ChrCAmain.f The commands to compile and execute ChrCA.p and CharCAmain.f character s*16 data s / "this is a string" / call ChrCA( s, %VAL(0), %VAL(15) ) write( *, "(A)" ) s stop end hostname% pc -c ChrCA.p hostname% f77 ChrCA.o ChrCAmain.f -lpfc -lpc ChrCAmain.f: MAIN: hostname% a.
8 A Pascal record of an integer and a character string matches a FORTRAN structure of the same. Consider these examples: The Pascal procedure, StruChr.p type lenstr = record nbytes: integer; chrstr: array [0..25] of char end; procedure struchr_(var v: lenstr); begin v.chrstr := 'oyvay'; v.nbytes := 5 end; { struchr_ } The FORTRAN main program, StruChrmain.f 1 The commands to compile and execute Struchr.p and StruChrmain.
8 Variant Records FORTRAN equivalents of variant records can sometimes 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.
8 The FORTRAN main program, VarRecmain.f. The variable ALIGN is integer*2, and is needed to match the Pascal variant record layout. The commands to compile and execute VarRec.p and VarRecmain.
8 Pascal Set Type The Pascal set type is incompatible with FORTRAN. Pascal intset Type The Pascal intset type is predefined as set of [0..127]. A variable of this type takes 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.
8 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) Value Parameters In general, Pascal passes value parameters on the stack.
8 See the following example: The Pascal procedure, SimVal.p. t, f, c, i, r, and s are value parameters. procedure simval_(t, f: boolean; c: char; i: integer; r: real; s: integer16; var reply: integer); begin reply := 0; { If nth arg is ok, set nth octal digit 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.
8 The commands to compile and execute SimVal.p and SimValmain.f hostname% pc -c SimVal.p hostname% f77 SimVal.o SimValmain.f -lpfc -lpc SimValmain.f: MAIN: hostname% a.out args=111111(If nth digit=1, arg n OK) Simple Types with the –xl Option With the -xl option, match Pascal real with FORTRAN real and Pascal integer with FORTRAN integer*2. You can pass by value using the %VAL() feature of FORTRAN.
8 Pascal procedure, ChrCAx.p procedure chrca_ ( a: array [lb..ub:integer] of char) ; begin a[0] := 'T' ; a[13] := 'o' ; end; { chrca_ } The FORTRAN main program, ChrCAmain.f The commands to compile and execute ChrCAx.p and ChrCAmain.f character s*16 data s / "this is a string" / call ChrCA( s, %VAL(0), %VAL(15) ) write( *, "(A)" ) s stop end hostname% pc -c ChrCAx.p hostname% f77 ChrCAx.o ChrCAmain.f -lpfc -lpc ChrCAmain.f: MAIN: hostname% a.
8 The FORTRAN main program, PassPtrmain.f. In the 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 PassPtrmain.
8 Simple Types The simple types pass in a straightforward way, as follows: The Pascal function, RetReal.p function retreal_(var x: real): real; begin retreal_ := x + 1 end; { retreal_ } The FORTRAN main program, RetRealmain.f The commands to compile and execute RetReal.p and RetRealmain.f without –xl double precision r, s, RetReal r = 2.0 s = RetReal( r ) write( *, "(2f4.1)") r, s stop end hostname% pc -c RetReal.p hostname% f77 RetReal.o RetRealmain.f -lpfc -lpc RetRealmain.f: MAIN: hostname% a.
8 Variable Parameters Pascal passes all var parameters by reference, the FORTRAN default. Simple Types Simple types pass in a straightforward manner, as follows: The FORTRAN subroutine, SimVar.f 186 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 Pascal 4.
8 The Pascal main program, SimVarmain.p program SimVarmain(output); var t, f: boolean; c: char; 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.
8 The FORTRAN subroutine, StrVar.f & & subroutine StrVar ( s10, s80, vls ) character s10*10, s80*80 structure /VarLenStr/ integer nbytes character a*25 end structure record /VarLenStr/ vls character ax*10, sx*80, vx*5 data ax / "abcdefghij" /, 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.
8 The commands to compile and execute StrVar.f and StrVarmain.p hostname% f77 -c StrVar.f StrVar.f: strvar: hostname% pc StrVar.o StrVarmain.p -lpfc -lF77 hostname% a.out abcdefghij abcdefghijklmnopqrstuvwxyz oyvay length(v)= 5 Character Dummy Arguments When you call FORTRAN 77 routines with character dummy arguments from Pascal programs—that is, routines in which string arguments are specified as character*(*) in the FORTRAN source, there is no explicit analogue in Pascal.
8 The following example illustrates this method: The Pascal program, sun.pas program Test(input,output); var s : string; procedure mygrout_(var prompt :string; length :integer32); external; begin writeln('Starting...'); s := 'Trio Jeepy'; mygrout_(s, 8); writeln('Ending...') end. The FORTRAN subroutine, mygrout.f The commands to compile and run this program 190 subroutine MyGrout(N) character*(*)N write(6,*) N return end hostname% pc -g -c sun.pas hostname% f77 -g sun.o mygrout.f -lpc mygrout.
8 Fixed Arrays For a fixed-array parameter, pass the same type and size by reference: The FORTRAN subroutine, FixVec.f 2 subroutine FixVec ( V, Sum ) integer Sum integer V(0:8) integer i Sum = 0 do 2 i = 0, 8 Sum = Sum + V(i) return end The Pascal main program, FixVecmain.p program FixVecmain(output); type VecTyp = array [0..
8 The univ Arrays The univ arrays that are in, out, in out, or var parameters pass by reference. The FORTRAN subroutine, UniVec.f The Pascal main program, UniVecmain.p subroutine UniVec ( V, Last, Sum ) integer V(0:2), Last, Sum, i Sum = 0 do i = 0, Last Sum = Sum + V(i) end do return end program UniVec; type VecTyp = array [0..9] of integer; procedure univec(var V:univ VecTyp; in Last: integer; var Sum: integer); external fortran; var Sum: integer; V: array [0..
8 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 Conformant Arrays Pascal-conformant array parameters are not compatible if Pascal calls FORTRAN.
8 Records and Structures Records and structures pass as follows: The FORTRAN subroutine, StruChr.f The Pascal main program, StruChrmain.p subroutine StruChr ( vls ) structure /VarLenStr/ integer nbytes character a*25 end structure record /VarLenStr/ vls vls.a(1:5) = 'oyvay' vls.nbytes = 5 return end 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.
8 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 Variant Records You can construct FORTRAN equivalents of variant records. There is some variation with architecture, and sometimes you need to adjust the alignment.
8 Chapter 6, “The C–Pascal Interface,” has an example that matches the following example. The FORTRAN subroutine, VarRec.f. The variable ALIGN is integer*2 and is needed to match the Pascal variant record layout.
8 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 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.
8 Simple Types With external fortran, the procedure name in the procedure statement and in the call must be in lowercase, with no underscore (_). The FORTRAN subroutine, SimVal.f 198 subroutine SimVal( t, f, logical*1 t, f character c integer*4 i double precision d integer*2 s integer*4 reply reply = 0 if ( t ) reply = if ( .not. f ) reply = if ( c .eq. 'z' ) reply = if ( i .eq. 9 ) reply = if ( d .eq. 9.9 ) reply = if ( s .eq. 9 ) reply = return end Pascal 4.
8 The Pascal main program, SimValmain.p program SimVal(output); var t: boolean := true; f: boolean := false; c: char := 'z'; i: integer := 9; r: real := 9.9; s: integer16 := 9; args: integer; 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.
8 Pointers Pointers are easy to pass, as shown in the following example: The FORTRAN subroutine, PassPtr.f. In the FORTRAN subroutine, the name is converted to lowercase. Uppsercase is ignored. The Pascal main program, PassPtrmain.p. In the Pascal program, where it calls the FORTRAN subroutine, the name must be in lowercase. subroutine PassPtr ( iPtr, dPtr ) integer i double precision d pointer ( iPtr, i ), ( dPtr, d ) i = 9 d = 9.
8 The 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 Function Return Values Function return values match types the same as with parameters, and they pass in much the same way. Simple Types The simple types pass in a straightforward way, as in this example: The FORTRAN function, RetReal.f double precision function retreal ( x ) retreal = x + 1.
8 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 Type shortreal You can return a shortreal function value between Pascal and FORTRAN. Pass it exactly as in the previous example, with the Pascal shortreal type matching the FORTRAN real type (without -xl).
8 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); begin y := x + 1 end; { AddOne } begin a := 8.0; b := 0.0; passproc(a, b, AddOne); writeln(a: 4: 1, b: 4: 1) end. { PassProcmain } The commands to compile and execute PassProc.f and PassProcmain.p hostname% f77 -c PassProc.f PassProc.f passproc hostname% pc PassProc.o PassProcmain.
8 Routines in other languages can be passed to Pascal; a dummy argument must be passed in the position normally occupied by the static link of the passed routine. If the passed routine is not a Pascal routine, the argument is used only as a placeholder. 204 Pascal 4.
9 Error Diagnostics This chapter discusses the errors you may come across while writing software programs with Pascal. It contains the following sections: Compiler Syntax Errors page 205 Compiler Semantic Errors page 210 Compiler Panics, I/O Errors page 217 Runtime Errors page 217 Note – Appendix B, “Error Messages,” lists in numerical order all the error messages generated by Pascal.
9 Most nonprinting characters in your input are also illegal, except in character constants and character strings. Except for the tab and formfeed characters, which are used to format the program, nonprinting characters in the input file print as the character ? in your listing. String Errors Encountering an end-of-line after an opening string quotation mark (') without first encountering the matching closing quote yields the diagnostic: Unmatched ' for string.
9 Replacements, Insertions, and Deletions When Pascal encounters a syntax error in the input text, the compiler invokes an error recovery procedure. This procedure examines the input text immediately after the point of error and uses a set of simple corrections to determine whether or not to allow the analysis to continue. These corrections involve replacing an input token with a different token or inserting a token. Most of these changes do not cause fatal syntax errors.
9 Undefined or Improper Identifiers If an identifier is encountered in the input but is undeclared, the error recovery mechanism replaces it with an identifier of the appropriate class. Further references to this identifier are summarized at the end of the containing procedure, function, or at the end of the program. This is the case if the reference occurs in the main program.
9 These are the error messages you receive when you compile synerr2.p. On line 6, parentheses are used for subscripting (as in FORTRAN), rather than the square brackets that are used in Pascal. The compiler noted that a was not defined as a procedure (delimited by parentheses in Pascal). Since you cannot assign values to procedure calls, pc diagnosed a malformed statement at the point of assignment. hostname% pc synerr2.p Mon Feb 13 11:02:04 1995 synerr2.
9 When you compile mism.p, the end-of-file is reached before an end delimiter hostname% pc mism.p E 26020-------^--- Malformed declaration 15130-------^--- Unexpected end-of-file - QUIT Compiler Semantic Errors The following sections explain the typical formats and terminology used in Pascal error messages.
9 Thus, if you try to assign an integer value to a char variable, you receive a diagnostic as follows: Mon Feb 13 13:16:20 1995 inchar.p: E 25190 line 6 - Type clash: integer is incompatible with char ... 25560: Type of expression clashed with type of variable in assignment In this case, one error produces a two-line error message. If the same error occurs more than once, the same explanatory diagnostic is given each time. The scalar Class The only class whose meaning is not self-explanatory is scalar.
9 Scalar Error Messages Error messages stating that scalar (user-defined) types cannot be read from and written to files are often difficult to interpret. In fact, if you define: type color = (red, green, blue) standard Pascal does not associate these constants with the strings red, green, and blue in any way. Pascal adds an extension so that enumerated types can be read and written; however, if the program is to be portable, you must write your own routines to perform these functions.
9 program expr_example(output); var a: b: c: p: A: B: set of char; Boolean; (red, green, blue); ^ integer; alfa; packed array [1..5] of char; begin b := true; c := red; new(p); a := []; A := 'Hello, yellow'; b := a and b; a := a * 3; if input < 2 then writeln('boo'); if p <= 2 then writeln('sure nuff'); if A = B then writeln('same'); if c = true then writeln('hue''s and color''s') end. { expr_example } This program generates the following error messages: hostname% pc expr.
9 Type Equivalence The Pascal compiler produces several diagnostics that generate the following message: non-equivalent types In general, Pascal considers types to be the same only if they derive from the same type identifier. Therefore, the following two variables have different types, even though the types look the same and have the same characteristics.
9 To make the assignment statement work, you must declare a type and use it to declare the variables, as follows: type r = record a: integer; b: char; end; var x: r; y: r; Alternatively, you could use the declaration: x, y : record a: integer; b: char; end; The assignment statement then works. Unreachable Statements Pascal flags unreachable statements. Such statements usually correspond to errors in the program logic, as shown in the following example: The Pascal program, unreached.
9 This error message is generated when you compile unreached.p. hostname% pc unreached.p Tue Feb 14 14:21:03 1995 unreached.p: w 18630 line 8 - Unreachable statement A statement is considered to be reachable if there is a potential path of control, even if it cannot be taken.
9 If you declare a label but never use it, Pascal gives you a warning. This is true even for a label declared in global scope. Compiler Panics, I/O Errors One class of error that rarely occurs, but which causes termination of all processing when it does, is a panic. A panic indicates a compiler-detected internal inconsistency. A typical panic message follows: pc0 internal error line=110 yyline=109 If you receive such a message, compilation is terminated.
9 : Bad data found on enumerated read : Bad data found on integer read : Bad data found on real read : Bad data found on string read : Bad data found on varying of char read : Cannot close file : Could not create file : Could not open file : Could not remove file : Could not reset file : Could not seek file : Could not write to file : File name too long (maximum of <
9 Argument to argv of is out of range Assertion # failed: Cannot close null file Cannot compute cos() Cannot compute sin() Cannot open null file Enumerated type value of is out of range on output Floating point division by zero Floating point operand is signaling Not-A-Number Floating point overflow Floating point underflow Illegal argument of to trunc Inexact floating point result Integer divide by zero Integer overflow Internal error i
9 Pointer value () out of legal range Ran out of memory Range lower bound of out of set bounds Range upper bound of out of set bounds Reference to an inactive file Second operand to MOD () must be greater than zero Statement count limit of exceeded Subrange or array subscript is out of range Sun FPA not enabled Unknown SIGFPE code Unordered floating point comparison Value of out of set bounds Varying length string index is out of range exp(
The XView Toolkit 10 This chapter introduces the XView programmer’s toolkit, a part of the XView application programmer’s interface (API). It assumes you are familiar with XView windows as a user, and introduces XView from a programmer’s point of view. For details, see the XView Programming Manual by Dan Heller, O’Reilly & Associates, Inc., 1990.
10 Tools This kit is a collection of functions. The runtime system is based on each application having access to a server-based Notifier, which distributes input to the appropriate window, and a Window Manager, which manages overlapping windows. There is also a Selection Service for exchanging data between windows (in the same or different processes). Objects XView is an object-oriented system. XView applications create and manipulate XView objects that are associated with XView packages.
10 with the root being the class from which all others are descended. In the XView toolkit, the root is the class Generic Object, which has no data fields and no methods. Each descendant of Generic Object is specialized in some way, perhaps with additional data fields or methods. What gives object orientation its power is that the inherited methods of a subclass can be reimplemented so that they take actions suited to the subclass.
10 Compiling with Libraries Most XView procedures you call are in the libraries pxview, xview, and X11. To compile an XView program, link the libraries, in order. For example: hostname% pc my_pascal.p -lpxview -lxview -lolgx -lX11 Header Files The header files define the necessary data types, constants, and external procedures necessary to write programs using the XView interface with Pascal. Names The names of the header file are the same as the XView C language header files with the .
10 Instead of these routines, the Pascal interface to XView defines a separate routine to get and set each attribute. • set—The routine to set an attribute is called set_attrname. Each set routine is a procedure, and takes as its first argument the object for which the attribute is being set. The second argument is the value of the attribute. • get—The routine to get the value of an attribute is called get_attrname. Each get routine is a function, and takes an XView object as the first argument.
10 Example calls are: Here, mymenu is an object of type XV_object. mymenu := xv_create (NULL, MENU, 0); ncols := get_MENU_NCOLS (mymenu); set_MENU_NITEMS (mymenu, items); xv_find_l (mymenu, MENU, attr_create_list_2s (MENU_DEFAULT,4)); xv_destroy (mymenu); The lists for Attr_avlist are created by functions that have the following names: attr_create_list_n() attr_create_list_ns() • • • • The n indicates the number of arguments the routine accepts. The number of arguments can be 1-16.
10 Coding Fragment Here is an example that illustrates the style of programming with the XView interface in Pascal.
10 The Straightforward Part—You can use the following items of information as you find them in the manual, with no change: • • • The XView procedure names The XView object names The XView object data types (except Boolean, see the following section) The More Complex Parts—You must make the following changes: • Any elementary C data type used must be converted to the corresponding Pascal data type.
10 Sample Translation of an XView Function to Pascal In the section, “Summary of Procedures and Macros,” in the XView Programming Manual, is the following entry: texsw_insert() Inserts characters in buf into textsw at the current insertion point. The number of characters actually inserted is returned. This will equal buf_len unless there was a memory allocation failure. If there was a failure, it will return 0.
10 Sample Program The following program, xview.p, makes a window: program hello(output); #include "stddefs_p.h" #include "attrgetset_p.h" var base_frame base_panel message text :Frame; :Panel; :Xv_panel_or_item_ptr; :string; begin text := 'Hello, World!'; xv_init(0); base_frame := xv_create(nil, FRAME, 0); base_panel := xv_create(base_frame, PANEL, 0); message := xv_create(panel, PANEL_MESSAGE, 0); set_PANEL_LABEL_STRING(message, text); window_main_loop(base_frame); end. {hello} To compile xview.
10 Menu Demo Program Here is a more complicated program, menu_demo.p, that makes a window and a panel with a menu button. The choices displayed are: Option 1, Option2, and Option 3. program MenuDemo(output); #include "stddefs_p.h" #include "attrgetset_p.
10 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_ITEM_MENU(button, menu); window_main_loop(base_frame); end.
Math Libraries 11 This chapter describes how to use the libm and libsunmath functions in Pascal programs. The math libraries are always accessible from a Pascal program because the Pascal compiler driver pc calls ld, the linker and loader, with the -lsunmath -lm options. If you compile Pascal program with the -v option, it prints the command-line used to call each of the compilation passes. For convenience, Pascal supports special Pascal header files, math_p.h and sunmath_p.
11 Contents of the Math Libraries Altogether, there are three math libraries: • libm.a—A set of functions required by the various standards to which the operating system conforms • • libm.so—(Solaris 2.x only) The shared version of libm.a libsunmath.a—A set of functions not required by the standards, but are of common use Table 11-1 lists the contents of the math libraries.
11 Table 11-1 Contents of Math Libraries (Continued) 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 Data conversions BSD miscellaneouss Base conversion routines (in libc) FORTRAN intrinsic functionss Legend: m Functions available in bun
11 The following Pascal program is an example of how to use math functions. program TestLibm(output); #include 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.
11 ieee_functions() The functions described in ieee_functions(3M) provide capabilities either required by the IEEE standard or recommended in its appendix. Example: program 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(remainder(d1, d1)); writeln(scalbn(d1, i1)); end.
11 program TestIEEEValues(output); #include "math_p.h" var l0: integer32 := 0; begin writeln('IEEE values'); writeln(infinity); writeln(signaling_nan(l0)); writeln(quiet_nan(l0)); writeln(max_normal); writeln(max_subnormal); writeln(min_normal); writeln(min_subnormal); end. ieee_retrospective() The libm function ieee_retrospective() prints to stderr information about unrequited exceptions and nonstandard IEEE modes. Pascal programs call ieee_retrospective() on exit by default.
11 program TestRandom(output); #include "math_p.h" var n: integer := 100; i: integer; ilb, { Lower bound } iub: integer; { Upper bound } ia: array [1..
11 • Division by zero—The divisor is zero, and the dividend is a finite non-zero number; or, more generally, an exact infinite result is delivered by an operation on finite operands. • Overflow—The correctly rounded result is larger than the largest number in the required precision. • Underflow—The number is too small, or precision is lost, and no signal handler is established for underflow. • Inexact—The rounded result of a valid operation is different from the infinitely precise result.
11 DOMAIN Argument domain exception SING Argument singularity OVERFLOW Overflow range exception UNDERFLOW Underflow range exception TLOSS Total loss of significance PLOSS Partial loss of significance If your matherr() function returns a non-zero result, no exception message is printed, and errno is not set. program TestMatherr(output); #include function matherr(var info: exception): integer; begin case info.
11 libsunmath Support for IEEE Modes and Exceptions ieee_handler() is used primarily to establish a signal handler for a particular floating-point exception or group of exceptions. The syntax of this function is described in the ieee_handler(3M) man page. This following Pascal program demonstrates how to abort on division by zero. program TestIEEEHandler(output); #include procedure DivisionHandler( sig: integer; sip: univ_ptr; uap: univ_ptr); begin writeln('Bad data - division by zero.
11 The syntax of this function is described in the ieee_flags(3M) man page. If an exception is raised at any time during program execution, then its flag is set, unless it is explicitly cleared. Clearing accrued exceptions is done by a call, as shown in the following Pascal program. program TestIEEEFlags(output); #include "math_p.h" var FlAction, FlMode, FlIn: string; FlOut: string_pointer; Zero: integer := 0; begin writeln(sqr(-1)); writeln(1 / Zero); writeln(exp(709.8)); writeln(exp(-708.
11 244 Pascal 4.
A Pascal Preprocessor This appendix describes the preprocessors, cpp(1) and cppas. cpp cpp(1) is the C language preprocessor. Pascal runs your source program through cpp(1) when you compile it without the –xl option. For a complete description of cpp(1), see the Solaris documentation. cppas The cppas preprocessor handles the Pascal conditional variables and compiler directives. You call cppas using the –xl option.
A A defined conditional variable is enabled (true) when it appears in either the %enable directive or in the –config option; otherwise, it is disabled (false), as in: %var one two %enable two The following section describes %var and %enable. Programs that contain conditional variables must be compiled with the –xl option. Compiler Directives A directive indicates some action for the compiler to take. You can use a directive anywhere in your program.
A Table A-1 cppas Compiler Directives (Continued) Compiler Directive Description %exit Stops processing 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.
A Example The Pascal program, config.p, which defines the conditional variables one and two program config_example(output); { This program demonstrates the use of the %config compiler directive. } var a: integer := maxint; b: integer := minint; %var one two begin 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.
A 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 never declared. Compilation failed The %debug Directive The %debug directive instructs pc to compile this line of code when you use the –cond compiler directive.
A Example The Pascal program, debug.p program 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.
A Example The 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.
A Comments If the expression in %if expression %then is false, pc skips over the %then part and executes the %elseif part instead. expression consists of a conditional variable and the optional boolean operators, and, or, and not. See the %else listing for examples of expression. Example 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.
A Syntax %ifdef expression %then . . %elseifdef expression %then . . %endif Comments If the expression in %ifdef expression %then is false, pc skips over the %then part and executes the %elseifdef part instead. expression consists of a conditional variable and the optional boolean operators, and, or, and not. See the %else listing for examples of expression. Example The Pascal program, ifdef.p, which first checks if bird1 has been defined. If not, it defines it with a %var directive.
A 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% a.out Bird two is a toucan. The %enable Directive The %enable directive sets a conditional variable to true. Syntax %enable var1 ...
A Example The Pascal program, 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:2, '.'); %endif end.
A Syntax %error 'string' Comments pc does not produce an object file. Example The Pascal 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.
A Comments If the compiler encounters an %exit directive within an include file, it stops processing the include file, but continues processing the source file in which it is included. In effect, %exit is equivalent to an end-of-file marker. When the compiler processes an %exit directive within an %if or %ifdef construct, it closes all %if or %ifdefs before it stops processing the current file. Example The Pascal program, exit_directive.p program exit_directive(output); begin writeln('Hello, world!') end.
A Comments When pc encounters a %if directive, it evaluates expression. If expression is true, pc executes the statements in the %then part. If expression is false, pc skips over the %then part and executes the %else, %elseif, or %endif directive. If no such directive exists, pc proceeds to the next statement. The expression consists of a conditional variable and the optional boolean operators and, or, and not. You can set a conditional variable on the command-line by using the -config option.
A Comments expression consists of a conditional variable and the optional boolean operators and, or, and not. See the %else listing for examples of expression. %ifdef is especially useful for determining whether or not a conditional variable has been declared in an include file. Example See the example in “The %elseifdef Directive.” The %include Directive The %include directive inserts lines from the specified file in the input stream.
A The module unit, include_mod.p module include_mod; define global, proc; %include 'extern.h'; procedure proc; begin writeln('From PROC global := global + 1; end; { proc } The include file, include.h : ',global); 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.
A Comments The %list directive and the -l compiler option perform the same function. Example The Pascal program, list.p program list_example(output); { This program demonstrates the use of the %list and %nolist directives. } %list; %include 'types.h'; %nolist; begin 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.
A The listing includes the time each unit was compiled and the name of each unit compiled. 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.
A The %slibrary Directive cppas treats %slibrary in the same manner as the %include directive. See “The %include Directive” on page 259. The %var Directive The %var directive defines conditional 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.
A Example The Pascal program, warning.p program warning_example(output); { This program demonstrates the 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' 264 Pascal 4.
Error Messages B The following is a list of the error messages produced by Pascal, arranged by message number.
B 10120: Too many arguments to 10130: Actual argument cannot be conformant array 10140: Actual argument is incompatible with formal var parameter of 10150: Actual argument is incompatible with formal parameter of 10160: Actual argument to NONPASCAL procedure cannot be conformant array 10170: Extra arguments to ADDR ignored 10180: Argument to must be of type , not 10190: Second argument to must be of typ
B 10290: Fourth argument to must be of type , not 10300: First argument to cannot be a univ_ptr 10310: argument to must be of type , not 10320: argument to must be unpacked 10330: argument to must be packed 10340: (line ) has arguments 10350: Transfer functions take exactly one argument 10360: sizeof takes at least 1 argument 10370: Formal arguments should be given only in
B 10470: ord's argument must be of scalar type, not 10480: 's argument must be of scalar type, not 10490: odd's argument must be an integer, not 10500: chr's argument must be an integer, not 10510: Argument to eoln must be a text file, not 10520: Argument to eof must be file, not 10530: Transfer functions take only one argument 10540: Arguments to must be variables, not expressions 10550: Read requires an argument 10560: Write requires an argume
B 10660: Second and successive arguments to must be constants 10670: Argument to must be a alfa, not 10680: halt takes no arguments 10690: stlimit requires one argument 10700: stlimit's argument must be an integer, not 10710: remove expects one argument 10720: remove's argument must be a string, not 10730: linelimit expects two arguments 10740: linelimit's second argument must be an integer, not 10750: linelimit's first argument must be a text file, not
B 10840: Illegal argument with format radix specification; probably a comma missing 11010: have incompatible conformant array schemas 11020: sizeof(conformant array) is undefined 11030: Conformant arrays are not allowed at ANSI Level 0 11040: Subscripting allowed only on arrays, not on s 11050: subrange value or array subscript () 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 v
B 11170: For-statement variable cannot be an element of a record 11180: .
B 12060: Width expressions allowed only in writeln/write calls 12070: Cannot write s with two write widths 12080: Can't write s with oct/hex 12090: First write width must be integer, not 12100: Second write width must be integer, not 12110: Negative widths are not allowed 12120: Cannot write unpacked array to textfile 12130: Can't read 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 t
B 13070: constant argument expected 13080: newline in string or char constant 13090: empty character constant 13100: too many characters in character constant 14010: Constant declarations should precede type, var and routine declarations 14020: Label declarations should precede const, type, var and routine declarations 14030: Type declarations should precede var and routine declarations 14040: All types should be declared in one type part 14050: All constants should be declared in one const part 14060: INTE
B 14140: PUBLIC ignored, procedure was declared INTERNAL or PRIVATE previously 14150: PRIVATE ignored, procedure was declared PUBLIC or as EXTERNAL previously 14160: For-statement variable must be declared in the block in which it is used 14170: All labels should be declared in one label part 14180: Expected identifier VARYING in declaration 14190: Variable declarations should precede routine declarations 14200: All variables should be declared in one var part 14210: public vars must be declare
B 14300: Expected keyword begin after declarations, before statements 14310: Improper initialization for variable 14320: is already defined globally 14330: Definition of name after applied use in 14340: Definition of name after applied use 14350: is already defined in this block 14360: Range lower bound exceeds upper bound 14370: '*' subrange descriptor used in illegal context 14380: Cannot initialize dynamic local variables 15010
B 15100: Cannot open #include file 15110: line does not exist in file 15120: End-of-file expected - QUIT 15130: Unexpected end-of-file - QUIT 16010: is not a function 16020: Too many levels of function/procedure nesting 16030: No assignment to the function variable 16040: Functions should not return s 16050: Procedure/function nesting too deep 16060: pcc_fvar(): no result for this function 16070: is a , not a function 16080: Illegal fun
B 16160: Procedure/function nesting too deep 16170: Can't call , its procedure or function not a pointer to a 16180: Can't call , it's not a procedure 16190: Procedure found where expression required 16200: Illegal procedure call, expecting value 16210: Non-pascal routine will fail if called indirectly from pascal 16220: Passing nested routine to non-pascal routine 16230: Can't call , its not a pointer to a pro
B 17100: Predecessor of is out of range 17110: Value of is out of range 17120: Range upper bound of out of set bounds 17130: Range lower bound of out of set bounds 17140: Value of out of set bounds 17150: value of (initial assign. to for loop variable) is out of range 17160: Value of (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 (* ...
B 18120: 8 or 9 in octal number 18130: Number too large for this implementation 18140: is undefined for reals 18150: cannot have more elements in z () than in a () 18160: is an unimplemented extension 18180: Initializer must be a string 18190: Initialization string is too long 18200: Expected 'options', not 18210: Unknown option ignored : 18220: Duplicate options specification : 18230: Unimplemented optio
B 18420: Undefined 18430: Undefined identifier 18440: Improper identifier 18450: Deleted 18460: Replaced with a 18470: Replaced id with a id 18480: Inserted 18490: Expected 18500: Label not defined in correct block 18510: Label redefined 18520: is undefined 18530: ^ allowed only on files and pointers, not on s 18540: Pascal uses [] for subscripting, not () 18550: Error occurred on q
B 18630: Unreachable statement 18640: Unrecoverable syntax error - QUIT 18650: Too many syntax errors - QUIT 18660: Input line too long - QUIT 18670: Unrecognizable # statement 18680: Include syntax error - expected ' or \" not found 18690: Absurdly deep include nesting - QUIT 18700: Too many levels of include nesting - QUIT 18710: Bad arbitrary base integer 18720: Bad base number, 18730: Digits required after decimal point 18740: Digits required before decimal point 18750: Digits required
B 19030: Missing program statement 19040: Input is used but not defined in the program statement 19050: Output is used but not defined in the program statement 19060: Program parameter is repeated 20010: Left operand of must be integer, real or set, not 20020: Right operand of must be integer, real or set, not 20030: Cannot mix sets with integers and reals as operands of 20040: Operands of must be Boolean or Integer 20050: Left operand of /
B 20140: Operands of must both be sets 20150: Set types of operands of must be compatible 20160: Incorrect statement usage const.
B 21070: Conformant array parameters in the same specification must be the same type 21080: actual parameter is not an array 21090: array index type is incompatible with conformant array parameter 21100: array index type is not within of index type of conformant array parameter 21110: array index type is not within range[..
B 21230: Program parameter is repeated 21240: Previous declaration for formal parameter '' has different type 21250: Previous declaration for formal parameter '' has different name '' 21260: Previous declaration for procedure '' had different number of formal parameters 21270: Formal cannot be qualified 21280: cannot be qualified 21290: Expression given, required for parameter 21300: Varia
B 22020: Ran out of memory (case) 22030: Ran out of memory (hash) 22040: Ran out of memory (TRIM) 22050: Ran out of memory (defnl) 22060: Ran out of memory (buffer_ir_pass) 22070: Ran out of memory (string) 22080: Ran out of memory (tralloc) 22090: out of memory (tstr) 22100: out of memory 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: is a non-standard function
B 23070: Routine Options are not standard 23080: External procedures and functions are not standard 23090: Separately compiled routine segments are not standard 23100: UNIV parameters are non-standard 23110: IN parameters are non-standard 23120: OUT parameters are non-standard 23130: IN OUT parameters are non-standard 23140: is a nonstandard function 23150: OTHERWISE clause in case statements is non-standard 23160: Ranges in case statements are non-standard 23170: Transfer functions are non-sta
B 23270: Storage Class non-standard 23280: Initialization in declaration part is non-standard 23290: UNIV_PTR types are non-standard 23300: '_' in an identifier is nonstandard 23310: Octal constants are non-standard 23320: is non-standard 24010: Cannot exit -- not within a loop 24020: For-statement variable must be unqualified 24030: For-statement variable cannot be an element of a record 24040: For-statement variable may be illegally changed at line
B 24120: Case selectors cannot be s 24130: Duplicate otherwise clause in case statement 24140: Case label type clashed with case selector expression type 24150: Multiply defined label in case, lines and 24160: No case-list-elements 24170: Bad case constant 24180: Range in case label must be in ascending order 24190: Maximum number of case selectors exceeded 24200: Cannot next -- not within a loop 24210: Goto
B 24300: Improper use of the DEFINE statement 24310: End matched on line 24320: Inserted keyword end matching {begin|record|class} on line 25010: {pack|unpack}: elements of a and z must have the same type 25020: component types of formal and actual arrays are not conformable 25030: Type of function (line ) 25040: Case label type clashed with case selector expression type 25050: Type clash: initializer must be a pointer 25060: Type clash: type of initializer does no
B 25150: Type clash: packed and unpacked set 25160: Type clash: files not allowed in this context 25170: Type clash: non-identical types 25180: Type clash: s with file components not allowed in this context 25190: Type clash: is incompatible with 25200: Type clash: string and unpacked array 25210: Type clash: string and packed array 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 d
B 25320: Function type should be given only in forward declaration 25330: Different type declared previously for function return 25340: Function type must be specified 25350: Type of expression in while statement must be Boolean, not 25360: Until expression type must be Boolean, not , in repeat statement 25370: Array index type incompatible with declared index type 25380: Too many subscripts 25390: Bad type of variable used for call 25400: Transfer functions only work on types of the sam
B 25490: types must be identical in comparisons operator was 25500: Index type clashed with set component type for 'in' 25510: Operands of + are of incompatible types 25520: Type names (e.g. ) allowed only in declarations 25530: Type name (e.g.
B 25670: Index type for arrays cannot be real 25680: Array index type is a , not a range or scalar as required 25690: Packed conformant array schema requires type identifier as element type 25700: Illegal type in VARYING array, only type CHAR allowed 25710: Size of type exceeds implementation limits 25720: Initializer must be a constant value of same type 26010: Malformed program statement 26020: Malformed declaration 26030: Malformed const declaration 26040: Malformed type declaration 26050: M
B 26140: Extension to WITH statement not allowed 27010: Integer overflow in constant expression The following are internal error messages. If any of them is displayed, contact Sun Customer Support.
B 296 Pascal 4.
Index A –a option to pc command, 24 a.
var parameters, 94, 117 C++ programming language, 137 to 162 arguments, passing of by reference, 139, 155 by value, 150, 157 arrays, fixed, 144 C++ calls Pascal, 138 to 155 character strings, 142 compatible types, 138 compiler options, 137 function return values, 152, 159 functions, 155 global variables in C++ and Pascal, 161 -lpc and -lc options, 137 name encoding, 138 parameter passing, 152 Pascal calls C++, 155 to 160 file pointers to C++, 162 interface, 137 records and structures, 146 value parameters,
–config option, 245, 252, 256 defined, 246 undefined, 245 %config directive, 247 –config option to pc command, 27, 246, 252 conformant arrays parameters between Pascal and C, 101, 114, 123 parameters between Pascal and C++, 152, 158, 159 parameters between Pascal and FORTRAN, 182, 193 conventions, xxi cpp #include directive, 67 the C preprocessor, 18, 27, 40, 49, 245 cppas, 245 to 263 compiler directives, 246 to 263 conditional variables, 245 preprocessor, 27, 40 the -xl preprocessor, 18, 19 D –D option to
300 in type equivalence, 214 out of memory, 217 runtime, 217 to 220 exception-handling function in math libraries, 240 executable file, 2, 9, 11, 18, 46 default, 9, 17 how to rename, 9 execution profile, 39 %exit directive, 256 expression diagnostics, 212 extended language features, 56 extern option, 86, 88 variable, 76 external option, See extern option interface, 163 procedures and functions as parameters, 202 to 204 records and structures, 175, 194 sharing declarations, 88 strings by value, 182 value p
identifier errors, 208 identifiers, 33, 46, 76 IEEE support functions in math libraries, 236 %if directive, 247, 257 %ifdef directive, 255, 257, 258 illegal characters, 205 #include directive, 67 %include directive, 259, 263 include file, 84, 257 and library header files, 74 as header file, 70 introduction, 67 producing a listing of, 32 search order, 32 to break a program up, 67 incompatible type errors, 210 inline(1) procedure call expander, 40 input, 10 to 13 installation, xix interface C++-Pascal, 137 C–
matherr() exception-handling function, 240 Pascal header files, 233 SPARC libraries, 238 memory, out of, 217 –misalign option to pc command, 34 module heading, 76 source files, 75 unit, 69 –mt option to pc command, 34 mv command, 9 N –native option to pc command, 35 -nocx option to pc command, 35 –nolib option to pc command, 35 –nolibmil option to pc command, 35 %nolist directive, 262 nonstandard floating point, 29 -noqueue licensing option, 5, 35 Notifier, XView, 222 -notrace option to pc command, 36 O –
–dalign option, 28 –dn option, 28 –dryrun option, 28 –dy option, 28 –fast option, 28 -flags option, 32 –fnonstd option, 29 -fns option, 29 -fround=r option, 29 -ftrap=t option, 30 -G option, 30 –G option, 30 –g option, 31 –H option, 31, 49 –help option, 32 –hname option, 31 –I option, 32 –i option, 32 -keeptmp option, 32 -Kpic and -KPIC options, 39 –L option, 33 –l option, 33, 261 -Ldirectory option, 33 –libmieee option, 34 –libmil option, 34 list of options, 23 to 66 -llib option, 34 –misalign option, 34 –
procedure and function type errors, 211 extern option, 86, 88 external, 88 linelimit, 25 type errors, 211 write, 46 program breakup of a, 67 logic errors, 215 source files, 75 unit, 68 programming object-oriented, 222 procedure-oriented, 222 public variable, 73, 80 Q –Qoption to pc command, 40 -qp option to pc command, 40 –Qpath option to pc command, 40 –Qproduce option to pc command, 40 queuing for a license, 5 QUIT errors, 209 R -R option to pc command, 41 range check on pointers, 31 reading and writing
#define, 27 assert, 25 stdin, 10 stdout, 10 string errors, 206 symbol errors, 208 table for dbx, 61 syntax errors and recovery, 205 to 207 T -tc option to pc command, 47 tcov(1) utility, 24 –temp option to pc command, 47 text editor textedit, 3 vi, 3 –time option to pc command, 48 type equivalence, errors, 214 shortreal, 154, 182 sizes, See sizes of types types compatible in C and Pascal, 90 compatible in C++ and Pascal, 138 compatible in FORTRAN and Pascal, 165 enumerated, 92, 166 incompatible, 210 set, 9
writing a Pascal program, 7 writing scalars, errors in, 212 X –xarch=a option to pc command, 49 –xcache=a option to pc command, 53 –xchip=c option to pc command, 54 –xF option to pc command, 55 –xildoff option to pc command, 56 –xildon option to pc command, 56 –xl option to pc command, 56, 245 –xlibmopt option to pc command, 57 -xlicinfo licensing option, 5 –xlicinfo option to pc command, 57 –xMerge option to pc command, 57 –xnolibmopt option to pc command, 57 -xregs=r option to pc command, 60 -xs option t
Index 307
Copyright 1995 Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, Californie 94043-1100 U.S.A. Tous droits réservés. Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, et la décompliation. Aucune partie de ce produit ou de sa documentation associée ne peuvent Être reproduits sous aucune forme, par quelque moyen que ce soit sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il en a.