User Tools

Site Tools


implicit_variables.htm
Navigation:  Language Reference > 3 - Variable Declarations > Special Data Types >====== Implicit Variables ====== Previous pageReturn to chapter overviewNext page

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).

There are two pragmas that affect implicits:

define(local_implicits⇒n)  n is on/off or 1/0. The Default value is “off”.

If the pragma is set to “on” or 1, implicit variables created within a ROUTINE (and not created in a parent Procedure) are considered as local to the ROUTINE. Therefore, implicit variables with the same name in different ROUTINEs are independent. If te pragma is set to “off” or 0, implicit variables created in a ROUTINE are considered as local to the parent Procedure. Therefore, all implicit variables are shared by all procedure ROUTINEs.

define(implicit_string_size⇒n)  n is a number. The Default value is 32.

This pragma defines the size of implicit string variables. n must be in the range 32..1024.

Example:

LOOP Counter# = 1 TO 10               !Counter# is an implicit LONG loop counter

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

END

Address“ = CLIP(City) & ', ' & State & ' ' & Zip  !Address” is an implicit STRING(32)  

Percent$ = ROUND((Quota / Sales),.1) * 100  !Percent$ is an implicit REAL

See Also:

Data Declarations and Memory Allocation

implicit_variables.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1