Data Declaration Sections

Top  Previous  Next

There are four general areas where data can be declared in a Clarion program:

• In the PROGRAM module, after the keyword PROGRAM and before the CODE statement. This is the Global data section.

• In a MEMBER module, after the keyword MEMBER and before the first PROCEDURE statement. This is the Module data section.

• In a PROCEDURE, after the keyword PROCEDURE and before the CODE statement. This is the Local data section.

• In a ROUTINE, after the keyword DATA and before the CODE statement. This is the Routine Local data section.

Global data is visible to executable statements and expressions in every PROCEDURE in the PROGRAM. Global data is always in scope. Global data is allocated Static memory and is available to every PROCEDURE in the PROGRAM.

Module data is visible only to the set of PROCEDUREs contained in the MEMBER module. It may be passed as a parameter to PROCEDUREs in other MEMBER modules, if required. Module data first comes into scope when any PROCEDURE in the MODULE is called. Module data is also allocated Static memory.

Local data is visible only within the PROCEDURE in which it is declared, or any Local Derived Methods declared within the PROCEDURE. Local data comes into scope when the PROCEDURE is called and goes out of scope when a RETURN statement (explicit or implicit) executes. It may be passed as a parameter to any other PROCEDURE. Local data is allocated Dynamic memory. The memory is allocated on the program's stack for variables smaller than the stack threshold (5K default), otherwise they are automatically placed onto the heap. This can be overridden by using the STATIC attribute, making its value persistent between calls to the procedure. FILE declarations are always allocated static memory (on the heap), even when declared in a Local Data section.

Dynamic memory allocation for Local data allows a PROCEDURE to be truly recursive, receiving a new copy of its local variables each time it is called.

Routine Local data is visible only within the ROUTINE in which it is declared. It may be passed as a parameter to any PROCEDURE. Routine Local data comes into scope when the ROUTINE is called and goes out of scope when an EXIT statement (explicit or implicit) executes. Routine Local data is allocated Dynamic memory. The memory is allocated on the program's stack for variables smaller than the stack threshold (5K default), otherwise they are automatically placed onto the heap. A ROUTINE has its own name scope, so the labels used for Routine Local data may duplicate variable names used in other ROUTINEs or even the procedure containing the ROUTINE. Variables declared in a ROUTINE may not have the STATIC or THREAD attributes.

See Also:

PROGRAM

MEMBER

PROCEDURE

CLASS

PROCEDURE Prototypes

STATIC

THREAD