Implicit Variables

Top  Previous  Next

Implicit variables are not declared in data declarations. They are created by the compiler when it first encounters them. Implicit variables are automatically initialized to blank or zero; they do not have to be explicitly assigned values before use. You may always assume that they contain blanks or zero before your program's first assignment to them. Implicit variables are generally used for: array subscripts, true/false switches, intermediate variables in complex calculations, loop counters, etc.

The Clarion language provides three types of implicit variables:

#

A label terminated by a # names an implicit LONG.

$

A label terminated by a $ names an implicit REAL.

"

A label terminated by a " names an implicit STRING(32).

Any implicit variable used in the global data declaration area (between the keywords PROGRAM and CODE) is Global data, assigned static memory and visible throughout the program. Any implicit variable used between the keywords MEMBER and PROCEDURE is Module data, assigned static memory and visible only to the procedures defined in the module. Any other implicit variable is Local data, assigned dynamic memory on the program's stack and visible only in the procedure. Implicits used in ROUTINEs incur more overhead than those not in ROUTINEs, so should be used sparingly, if at all.

Since the compiler dynamically creates implicit variables as they are encountered, there is a danger that problems may arise that can be difficult to trace. This is due to the lack of compile-time error and type checking on implicit variables. For example, if you incorrectly spell the name of a previously used implicit variable, the compiler will not tell you, but will simply create a new implicit variable with the new spelling. When your program checks the value in the original implicit variable, it will be incorrect. Therefore, implicit variables should be used with care and caution, and only within a limited scope (or not at all).

Example:

LOOP Counter# = 1 TO 10               !Implicit LONG loop counter

ArrayField[Counter#] = Counter# * 2  !to initialize an array

END

 

Address" = CLIP(City) & ', ' & State & ' ' & Zip

!Implicit STRING(32)

 

MESSAGE(Address")

!Used to display a temporary value

 

Percent$ = ROUND((Quota / Sales),.1) * 100

!Implicit REAL

 

MESSAGE(FORMAT(Percent$,@P%<<<.##P))

!Used to display a temporary value

 

See Also:

Data Declarations and Memory Allocation