Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/ftp/documents/system-docs/vms-guide/html/VUG_45.html
Дата изменения: Wed Nov 1 17:38:26 1995
Дата индексирования: Sun Dec 23 18:30:37 2007
Кодировка:

Поисковые слова: р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п
Programming Languages



Software

Programming Languages


VMS users
have the following compilers available: C, C++, Pascal, FORTRAN, and MACRO--which is a low-level language. There are four steps to creating a program:

  1. Create a source file containing valid program statements as defined by the language. Source files are usually created in whatever editor you choose to use, such as DECTPU (page 69) or Emacs (page 80).

  2. Compile the source program to create an object file. This file will have a file type of .OBJ.

  3. Link the object file to create an executable image. The executable code has a file type of .EXE.

  4. Run the program.

If you create a program file, for example, called RECALC.FOR, then you would use the following commands to compile, link, and execute the program:

$ FORT RECALC 
$ LINK RECALC 
$ RUN RECALC
When you write your programs, your source files should always have a file type that identifies the programming language being used. This makes it easier to invoke the compiler because you do not need to specify the file type. The following table lists the file types used under VMS.

Table 7.1: Source File Types

A debugging program is available that lets you control the execution of programs and monitor their progress as they execute. If any error occurs during execution, the program remains in the debugger letting you examine the values of variables and other features in order to identify errors. The debugger can also be used in step-through mode, which lets you check the program's status after each line of code is executed.

The debugger is used by specifying the /DEBUG option during both the compile and link steps. (An example of using the /DEBUG option is provided in the description of FORTRAN on page 127). After successfully debugging a program, you should recompile and relink it without the /DEBUG option so that the program will run more efficiently.*1

C

C was developed by AT&T Bell Laboratories under the Unix operating system but was designed to be portable across different systems. The language is described in detail in numerous books. One of the most widely used, The C Programming Language, by Brian Kernighan and Dennis Ritchie, is available in the STScI library.

The C language has no native input or output facilities; these are provided by a run-time library. Before you can use the C compiler under VMS, you must set up the necessary logicals. To do this you can put the following line in your LOGIN.COM file (or you can type it in during every session in which you plan to compile C programs):

$ DEFINE LNK$LIBRARY SYS$LIBRARY:VAXCRTL
Writing and running a C program is a four-step process:

  1. Write the source file using your favorite editor.

  2. Run the compiler.

  3. Link the object code.

  4. Run the executable code.

The following example shows how to run a program called CALCULATE. Note that in this example, file types are used. File types are optional, for example, the command $ link calculate would be the same as $ link calculate.obj.



$ DEFINE LNK$LIBRARY SYS$LIBRARY:VAXCRTL 
$ CC CALCULATE.C 
$ LINK CALCULATE.OBJ 
$ RUN CALCULATE.EXE
A discussion of the features or syntax of the C language is beyond the scope of this manual; you should refer to the Kernighan and Ritchie book (or another text) for that information. Online help is also available. Type HELP CC at the system prompt. The following example shows an extremely simple C program (but one that works).

#include stdio.h
main() 
{
   int answer;
   answer = 2 +3 ; 
   printf("The answer is %d.", answer); 
}

C++

C++ is an object-oriented C compiler. Two implementations are available at the Institute: Digital's version of C++, which is invoked by the cxx command, and GNU's version, called G++, which is invoked by the gxx command. The C++ compilers may not yet be available on all systems at the Institute. A reference book, The C++ Programming Language, by Bjarne Stroustrup, is available in the STScI Library.

FORTRAN

DECFortran is available on most systems at STScI. Compiling, linking, and running FORTRAN programs is done in exactly the same way as for C. FORTRAN programs should usually have a file type of .FOR. The following example shows how a FORTRAN program file called COMPUTE.FOR would be compiled, linked, and run, with the optional debugger specified:

$ FORTRAN/DEBUG/NOOPTIMIZE COMPUTE 
$ LINK/DEBUG COMPUTE 
$ RUN COMPUTE 

Pascal

The Pascal language is a structured language with flexible variable types and user-definable procedures and functions. Pascal source files should all have a file type of .PAS.

Once you create a Pascal source file--using your favorite editor--you need to run the compiler, link the object code, and run the executable image.

The Pascal compiler is run by typing the PASCAL command. The following shows a sample Pascal run.

$ PASCAL COMPUTE.PAS
$ LINK COMPUTE
$ RUN COMPUTE

MACRO

MACRO is used in the same way as any of the previously-described languages. If you are interested in the MACRO language, you should see the VAX MACRO and Instruction Set Reference Manual. Users create a source file of MACRO statements and then compile, link, and run, the file.

The MACRO compiler is run by typing the MACRO command. The following shows a sample run (using the VAX MACRO assembler).

$ MACRO FILE.MAR 
$ LINK FILE 
$ RUN FILE
There are two MACRO compilers:
one for VAX systems and one for Alpha (AXP) systems. The VAX MACRO assembler (MACRO-32) is used by default on VAX systems and can be used from an Alpha to compile VAX assembly language source. If you are using an AXP host, you can use the /ALPHA qualifier when invoking the MACRO compiler to use the MACRO-64 assembler.

Table 7.1: - Source File Types
C
C++
FORTRAN
Pascal
MACRO

Generated with CERN WebMaker