Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

SAVE (statement and attribute)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Stores variables in static memory.

Syntax

A type declaration statement with the SAVE attribute is:

type , attrib-list :: save-list
type

is a valid type specification (INTEGER, REAL, LOGICAL, CHARACTER, TYPE (name), etc.).

attrib-list

A comma-separated list of attributes including SAVE and optionally those attributes compatible with it, namely:

Table 10-49 Title not available (SAVE (statement and attribute))

ALLOCATABLE

PRIVATE

TARGET

DIMENSION

PUBLIC

VOLATILE

POINTER

STATIC

 

save-list

is a comma-separated list of names of objects to save.

The syntax of the SAVE statement is:

SAVE [[::] save-list]

Description

The SAVE statement and attribute cause objects in a subroutine or function to be stored in static memory, instead of being dynamically allocated whenever the procedure is invoked (the default case). A saved object retains its value and definition, association, and allocation status between invocations of the program unit in which the saved object is declared.

If save-list is omitted, everything in the scoping unit that can be saved is saved. No other explicit occurrences of the SAVE attribute or the SAVE statement are allowed.

The names of the following may appear in save-list:

  • Scalar variables

  • Arrays

  • Named common blocks

  • Derived type objects

  • Records

If the name of a common block appears in save-list, it must be delimited by slashes (for example, /my_block/); all variables in the named common block are saved. If a common block is saved in one program unit, it must be saved in all program units (except main) where it appears.

HP Fortran always saves all common blocks.

The following must not appear in save-list:

  • Formal argument names

  • Procedure names

  • Selected items in a common block

  • Variables declared with the AUTOMATIC statement or attribute

  • Function results

  • Automatic data objects (such as automatic arrays, allocatable arrays, automatic character strings, and Fortran 90 pointers)

Initializing a variable in a DATA statement or in a type declaration statement implies that the variable has the SAVE attribute, unless the variable is in a named common block in a block data subprogram.

A SAVE statement in a main program unit has no effect.

Examples

The SAVE statement in the following example saves the variables a, b, and c, as well as the variables in the common block dot:

SUBROUTINE matrix
SAVE a, b, c, /dot/
RETURN

The SAVE statement in the next example saves the values of all of the variables in the subroutine fixit:

SUBROUTINE fixit
SAVE
RETURN

Related statements

AUTOMATIC and STATIC

Related concepts

For related information, see the following:

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.